实例:
技术栈:三大组件、Vue
涉及知识点:Vue-CLI、组件通信、全局事件总线、自定义事件、消息发布与订阅、本地存储
// main.js
// 项目入口
// 引入Vue
import Vue from 'vue'
// 尹瑞App组件
import App from './App.vue'
Vue.config.productionTip = false
// 创建Vue实例对象--vm
// new Vue({
// render: h => h(App),
// }).$mount('#app')
new Vue({
el: '#app',
render: h=>h(App),
beforeCreate(){
// 安装全局事件总线
Vue.prototype.$bus = this;
}
})
// App.vue
<template>
<div id="root">
<div class="todo-container">
<div class="todo-wrap">
<MyHeader @addTodo='addTodo'/>
<!-- 传给子组件 -->
<!-- <MyList :todos='todos' :checkTodo='checkTodo' :deleteTodo='deleteTodo'/> -->
<MyList :todos='todos'/>
<MyFooter :todos='todos' @checkAllTodo='checkAllTodo' @clearAllTodo='clearAllTodo'/>
</div>
</div>
</div>
</template>
<script>
import pubsub from 'pubsub-js';
import MyHeader from './components/MyHeader.vue';
import MyList from './components/MyList.vue';
import MyFooter from './components/MyFooter.vue';
export default {
name: 'App',
// 注册
components: {
MyHeader,
MyList,
MyFooter,
},
data(){
return {
// todos:[
// {id:'001',title:'吃饭',done:true},
// {id:'002',title:'睡觉',done:false},
// {id:'003',title:'学习',done:true},
// ]
todo