Vue 2.0设置路线 - 不要将'new'用于副作用 [英] Vue 2.0 setting up routes - Do not use 'new' for side effects

查看:96
本文介绍了Vue 2.0设置路线 - 不要将'new'用于副作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在配置一个vue项目。我使用了webpack模板。 (npm install init webpack)。我在终端收到错误 -

I am configuring a vue project. I used the webpack template. ( npm install init webpack ). I am getting an error in the terminal --

ERROR in ./src/main.js

✘  http://eslint.org/docs/rules/no-new  Do not use 'new' for side effects  
/Users/uz067252/Documents/Development/Vue/workex/vue-project/src/main.js:21:1
new Vue({
^


✘ 1 problem (1 error, 0 warnings)


Errors:
1  http://eslint.org/docs/rules/no-new

这是main.js

import Vue from 'vue'
import App from './App.vue'
import Hello from './components/Hello.vue'

import VueRouter from 'vue-router'
import VueResource from 'vue-resource'

// We want to apply VueResource and VueRouter
// to our Vue instance
Vue.use(VueResource)
Vue.use(VueRouter)

// Pointing routes to the components they should use
var router = new VueRouter({
routes: [
    { path: '/hello', component: Hello },
    { path: '*', redirect: '/hello' }
]
})

new Vue({
el: '#app',
router: router,
render: h => h(App)
})

谢谢

推荐答案

该错误来自您的eslint代码格式化程序,而不是来自Vue.js本身。

That error is coming from your eslint code formatter, not from Vue.js itself.

您的webpack环境配置为在构建和启动应用程序之前验证代码。在执行此操作时,您的 eslint 会发出警告。

Your webpack environment is configured to verify code before it builds and starts your app. While doing that, your eslint put out that warning.

为避免这种情况,请执行以下操作(在的最后5行中> main.js 文件):

To avoid it, do as follows (in the last 5 lines of your main.js file):

new Vue({  // eslint-disable-line no-new
    el: '#app',
    router: router,
    render: h => h(App)
})

您在上面所做的只是禁用 new 的eslint警告上面的那一行。现在您的webpack将正常启动您的应用程序。

What you are doing above is disabling eslint warning for new only in that above line. Now your webpack will start your app normally.

另一种选择是在 .eslintrc.js 中设置规则(在项目根文件夹中),您可以在其中指定应忽略 no-new 规则。 (在这种情况下不推荐)

The other option is to set a rule in .eslintrc.js (in the project root folder), where you can specify that no-new rule should be ignored. (not recommended in this case)

这篇关于Vue 2.0设置路线 - 不要将'new'用于副作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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