## 傳值
父組?件通過屬性的方式向子組件傳遞數據. vue中有單向數據流的概念,父組件可以向子組件傳值,子組件只能去用這個數據,但是不要去修改父組件傳遞過來的值.
子組件通過this.$emit()向父組件傳值.
```
<div id="app">
<counter :number="1" @change="add"></counter>
<counter :number="1" @change="add"></counter>
{{total}}
</div>
<script>
var counter = {
props: ['number'],
data: function () {
return {
n: this.number,
};
},
template: `
<div>
{{n}}
<input type="button" value="add" @click="add">
</div>
`,
methods: {
add: function () {
this.n += this.number;
this.$emit('change', 1);
}
}
};
new Vue({
el: '#app',
data: {
total: 2,
},
components: {
counter,
},
methods: {
add: function (value) {
this.total += value;
}
}
})
</script>
```
- 基礎
- MVVM
- 前端組件化
- VUE實例
- 生命周期
- 指令
- v-bind
- 模板語法
- 使用樣式
- class樣式
- 內聯樣式
- v-for
- v-if和v-show
- 過濾器
- 計算屬性
- 方法偵聽器
- 計算屬性的set和get
- watch,computed,methods對比
- 樣式綁定
- 條件渲染
- 組件
- 組件化和模塊化區別
- 使用組件的細節
- 父子組件數據傳遞
- 組件參數校驗與非props特性
- 給組件綁定原生事件
- 非父子組件間的傳值
- 在vue中使用插槽
- 作用域插槽
- 動態組件與v-once指令
- 動畫特效
- vue中CSS動畫原理
- 使用animate
- 同時使用過度和動畫
- JS動畫與velocity的結合
- 多個元素或組件的過度
- vue列表過度
- 動畫封裝
- 路由
- 什么是路由
- VUEX
- 概述
- 安裝
- 訪問倉庫