1.父组件与子组件之间的数据传递
首先:父组件里面引入了子组件,举个例子,父组件是A,子组件是B,A需要 import B from ‘子组件B的文件路径‘,
并且在注入父组件的components对象里
![](https://img.haomeiwen.com/i17713086/ae92bbf61214311f.png)
其次调用子组件B,并将需要传递的值附在调用的子组件B上
![](https://img.haomeiwen.com/i17713086/e4f18af7e62b7172.png)
然后子组件B接受这个值:props:{}
![](https://img.haomeiwen.com/i17713086/c7299978a6404181.png)
2.子组件与父组件之间的 数据传递
子组件需要发送一个事件让父组建能够接收到---$emit
![](https://img.haomeiwen.com/i17713086/d8cb83a116d707dc.png)
父组件接收change这个事件
![](https://img.haomeiwen.com/i17713086/6f6b206374918c02.png)
这边点击子组件那个元素它的文本这边就可以打印出来了~
![](https://img.haomeiwen.com/i17713086/94829a05ea099bd3.png)
3.通过父组件实现子组件与子组件之间的数据传递
![](https://img.haomeiwen.com/i17713086/b6d118446143d2a9.png)
这时候父组件已经接收到子组件B传过来的文本变量letter了,组件A需要绑定这个letter,并且子组件A页面里呢需要接收这个letter ,props{},如图“”2请先忽略 letter“”所示,并且需要watch(监听器)这个变量letter,如下图做所示:
![](https://img.haomeiwen.com/i17713086/4e29c35ea21d0182.png)
状态管理模式--vuex
![](https://img.haomeiwen.com/i17713086/1dc94fae160acc0f.png)
![](https://img.haomeiwen.com/i17713086/0f98c0d8ad32daae.png)
1.先要全局引入注册store,本地是在main.js引入注册的
import store from './store/travel'
new Vue({
el: '#app',
·······
store,
components: { App },
template: '<App/>'
})
2.然后创建一个store
![](https://img.haomeiwen.com/i17713086/30af01398cc74af5.png)
3.调用
![](https://img.haomeiwen.com/i17713086/df61abaaf63a469c.png)
网友评论