1、创建方法新建 /Global 目录,在里面新建 index.js 文件用来存放自定义全局方法,方法名推荐使用 $ 开头以便区分。index. jsexport default { install(Vue, ) { // 验证规则 Vue.prototype.$keyRule = function (rule) { return /^[a-zA-Z0-9_-]{6,20}$/.test(rule); } }2、入口文件引入main.js// 全局方法 import Global from './Global' // 引入 Vue.use(Global)
this.$router.push()描述:跳转到不同的url,但这个方法会向history栈添加一个记录,点击后退会返回到上一个页面。// 字符串 this.$router.push('home'); // 对象 this.$router.push({ path: 'home' }); // 命名的路由,带参数 this.$router.push({ name: 'user', params: { userId: 123 }}); // 带参数,变成 /user?id=123 this.$router.push({ name: 'user', query: { userId: 123 }}
在 NPM 包的 dist/ 目录你将会找到很多不同的 Vue.js 构建版本。这里列出了它们之间的差别: UMDCommonJSES Module (基于构建工具使用)ES Module (直接用于浏览器)完整版vue.jsvue.common.jsvue.esm.jsvue.esm.browser.js只包含运行时版vue.runtime.jsvue.runtime.common.jsvue.runtime.esm.js-完整版 (生产环境)vue.min.js--vue.esm.browser.min.js只包含运行时版 (生产
演示使用{ path: '/ChangePwd', name: 'ChangePwd', component: ChangePwd, meta: { title: '修改密码', icon: 'icon-lock' } },获取this.$route.meta.title this.$route.meta.icon../../md/Vue/