亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何正確使用Vue.js的組件?

如何正確使用Vue.js的組件?

ibeautiful 2018-10-01 09:05:48
如何正確使用Vue.js的組件
查看完整描述

1 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

  1. # 下載最新的vue
    $ npm install vue


  2. js 引用 vue.js


  3. 開始代碼,感受vue強大的雙向數據綁定



1234567891011<div id="app">  <p>{{ message }}</p>  <input v-model="message"></div>     new Vue({  el: '#app',  data: {    message: 'Hello Vue.js!'  }})




實戰代碼:

12345678910111213141516171819202122232425262728293031<div id="app">  <input v-model="newTodo" v-on:keyup.enter="addTodo">  <ul>    <li v-for="todo in todos">      <span>{{ todo.text }}</span>      <button v-on:click="removeTodo($index)">X</button>    </li>  </ul></div>     new Vue({  el: '#app',  data: {    newTodo: '',    todos: [      { text: 'Add some todos' }    ]  },  methods: {    addTodo: function () {      var text = this.newTodo.trim()      if (text) {        this.todos.push({ text: text })        this.newTodo = ''      }    },    removeTodo: function (index) {      this.todos.splice(index, 1)    }  }})




Vue整個生命周期示意圖:




查看完整回答
反對 回復 2018-10-21
  • 1 回答
  • 0 關注
  • 717 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號