事件侦听器
<script>
export default {
mounted() {
this.creatInterval('hello')
this.creatInterval('world')
},
creatInterval(msg) {
let timer = setInterval(() => {
console.log(msg)
}, 1000)
this.$once('hook:beforeDestroy', function() {
clearInterval(timer)
})
}
}
</script>
$attr 透传
手动挂载 vm.$mount
路由参数解耦
props: true
const router = new VueRouter({
routes: [{
path: '/user/:id',
component: User,
props: true
}]
})
// 使用
export default {
props: ['id'],
methods: {
getParamsId() {
return this.id
}
}
}