1.关于vue的生命周期
看官网的图:
地址:https://cn.vuejs.org
2.vue的双向数据绑定+实现
var obj = {}
Object.defineProperty(obj, 'txt', {
get: function () {
return obj;
},
set: function (newValue) {
document.getElementById('txt').value = newValue
document.getElementById('show-txt').innerHTML = newValue
}
})
document.addEventListener('keyup', function (e) {
obj.txt = e.target.value
const b = []
b.push(1)
console.log(b);
})
实现效果:
3.vue父子组件的相互通信
父亲组件传值给子组件:
父组件在data里面的数据:
子组件获取父组件里面的data:
props:['menuList','footerBgcolor'],
子组件在html中直接使用:
class="footer" :style="{
background:footerBgcolor}">
class="footer-menu" v-for="(menu, index) in menuList" :key="index">
@click.native="selectMenu(menu)" :to="menu.path">{
{menu.title}}
子组件向父组件传值:
子组件添加触发函数,也可以是生命周期函数:
@click.native="selectMenu(menu)"
在子组件的方法函数中加入:
this.$emit('changeTitle',menu);//第一个参数
在父组件接受:
class="content" @changeTitle="changeTitle" >
在父组件的data中定义接受的变量:
data(){
return{
selectMenu:{},
}
}
在父组件实现方法:
changeTitle(menu){
// console