vue细节点

Posted by monkey-yu on September 14, 2020 | 浏览量: -

1. vuejs里面的变量如何在浏览器的console中查看?

解决方案:

在main.js文件里声明window.Vue = new Vue

1
2
3
4
5
6
7
window.Vue = new Vue ({
  el:'#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})

在控制台里用Vue就可以访问了。

2.设置一个全局的属性绑定在Vue上

解决方案:

在main.js文件里去设置vue的全局属性

1
2
3
4
5
import { hasPermission } from './utils/hasPermission';

Vue.use(ElementUI, {locale});
//设置全局属性
Vue.prototype.hasPerm = hasPermission
1
2
3
4
5
6
// hasPermission.js 文件
import store from '../store';
export function hasPermission(permission){
  let myPermissions = store.getters.permissions;
  return myPermission.indexOf(permission) > -1;
}