Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app" class="wrap">
  <form>
    <ul>
      <li>
        <label>姓名
          <input type="text" v-model.trim="userName"  placeholder="請輸入姓名" />
        </label>
      </li>
      <li>
        <label>密碼
          <input type="password" v-model.trim="userPassword" placeholder="請輸入密碼" />
        </label>
      </li>
    </ul>
  </form>
  <a href="#" class="btn" @click.prevent="getData">取得使用者資料</a>
  <a href="#" class="btn" @click.prevent="postData">儲存使用者資料</a>
</div>

              
            
!

CSS

              
                .wrap {
  font-family: '微軟正黑體';
  font-size: 15px;
  padding: 20px
}

.btn {
  margin: 0 5px 0 0;
}

li {
  margin-bottom: 20px;
}
              
            
!

JS

              
                new Vue({
  el: '#app',
  data: {
    userName: '',
    userPassword: ''
  },
  methods: {
    getData: function() {
      let mock = new AxiosMockAdapter(axios)
      let _this = this
      
      mock.onGet('/user?id=123').reply(200, {
        name: 'John Smith',
        password: '123456789' 
      });      
      
      axios
        .get('/user?id=123')
        .then(function (response) {
          _this.userName = response.data.name
          _this.userPassword = response.data.password
          alert(`使用者姓名是 ${response.data.name},密碼是 ${response.data.password}`)
        })
        .catch(function (error) {
          alert('取得資料失敗')
        })
    },
    postData: function() {
      let mock = new AxiosMockAdapter(axios)
      let _this = this
      
      mock.onPost('/user').reply(200, {
        id: 2, 
        name: 'Hello World'
      })
      
      axios
        .post('/user', {
          name: this.userName,
          password: this.userPassword
        })
        .then(function (response) {
          alert(`成功送出資料,使用者姓名是 ${_this.userName},密碼是 ${_this.userPassword}`)
        })
        .catch(function (error) {
          alert('送出失敗')
        });
    }
  }
});
              
            
!
999px

Console