Vue——自定义事件
由于Vue中的其他组件无法使用到Vue实例中的数据,可以通过自定义事件完成对Vue实例中数据的一些操作,具体图解如下:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/24e02bc87dfaebd6007ebf2c04e5a6f9.png)
其中,由于Vue中具有的数据双向绑定的特性,使得前端可以作为组件与实例的桥梁,利用自定义事件实现一些功能。
示例代码:
//前端
<div id="app" >
<todo>
<todo-title slot="todo-title" :title="title"></todo-title>
<todo-items slot="todo-items" v-for="(item,index) in items" :item