import Vue from 'vue' import App from './App.vue' import router from './router' new Vue({ el: '#app', render: h => h(App), router })
当使用eslint校验运行上面这段代码时(该代码在src/main.js文件中),会报错
✘ http://eslint.org/docs/rules/no-new Do not use 'new' for side effects
src/main.js:8:1
new Vue({
两种方法解决该问题:
方法一:定义一个变量xxx(可为任意值)接收新创建的Vue
let xxx = new Vue({ el: '#app', render: h => h(App), router }) Vue.use({ xxx })
方法二:在new Vue的上方添加一行注视,让eslint不检查"no-new"
import Vue from 'vue' import App from './App.vue' import router from './router' /* eslint-disable no-new */ new Vue({ el: '#app', render: h => h(App), router })