mvvm模式
双向绑定原理
var data={}
document.querySeletor("#ipn").oninput=function(e){
data.name=e.target.value
}
Object.defineProperty(data,'name',{
get:function(){
return this.name
},
set:function(value){
this.name=value
document.querySeletor("#box").innerHTML=value
document.querySeletor("#ipn").value=value
}
})
Vue.extend使用
- Vue.extend(组件)
- 返回的是一个构造函数
- 不能直接使用,还需实例化(通过new关键字)
- 实例化出来的就是包含传入的组件特性
- $mount(选择器)
- 直接找到该组件,并把组件添加进去
- $mount是基于组件的tempalte生成的dom结构
路由钩子函数
- 全局钩子函数
router.beforeEach((to,from,next)=>{
next()
}
router.afterEach((to,from)=>{
})
- 路由对应组件钩子函数
beforeRouteEnter((to,from,next)=>{
next()
})
beforeRouteUpdata((to,from,next)=>{
next()
})
beforeRouteLeave((to,from,next)=>{
next()
})
- 路由配置钩子函数
beforeEnter((to,from,next)=>{
next
})