vue.js - 为什么vue-router中的钩子函数没有触发?

查看:525
本文介绍了vue.js - 为什么vue-router中的钩子函数没有触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

这是我的main.js

import Vue from 'vue';
import VueRouter from 'vue-router';
import App from './App';
import Index from './views/index';

Vue.use(VueRouter);

let app = Vue.extend({
    components: { App }
});

let router = new VueRouter({
    hashbang: false
});

router.map({
    '/home': {
        name: 'home',
        component: Index
    }
});

router.start(App, '#app');

index.vue

<template>
    <p>im index</p>
</template>

<script>
export default {
    route: {
        active(transition) {
            console.log('yo im active');
            transition.next();
        },
        deactive(transition) {
            console.log('yo im deactive');
            transition.next();
        }
    }
}
</script>

<style lang="css">
</style>

切换路由的时候钩子函数没有触发,是哪里用错了吗?

解决方案

亲,是activate,deactivate,不是active,deactive

这篇关于vue.js - 为什么vue-router中的钩子函数没有触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆