扫码关注官方订阅号
认证高级PHP讲师
router 和 store 一樣都可以手動暴露出來直接調用,例如
router
store
// 路由設定 var router = new VueRouter({ mode: 'history', root: '/dashboard', linkActiveClass: 'active', routes }) router.beforeEach((to, from, next) => { console.log(to.path) next() }) new Vue({ el: '#app', router, store, render: h => h(require('./components/App.vue')) }) // 暴露出來 export { router, store }
那在任何地方都可以進行調用,其實我們把 store, router 放進 new Vue() 裡面也只是單純注入盡各組件而已,本質上沒啥差別。
new Vue()
import { router, store } from '../app.js' router.push('/some/where')
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
router和store一樣都可以手動暴露出來直接調用,例如app.js
那在任何地方都可以進行調用,其實我們把
store,router放進new Vue()裡面也只是單純注入盡各組件而已,本質上沒啥差別。