首页 > 其他 > 详细

解决vue项目eslint校验 Do not use 'new' for side effects 的两种方法

时间:2018-10-29 21:11:37      阅读:200      评论:0      收藏:0      [点我收藏+]
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
})

 

参考博客及评论

https://www.cnblogs.com/xzma/p/7727412.html

解决vue项目eslint校验 Do not use 'new' for side effects 的两种方法

原文:https://www.cnblogs.com/xinzaimengzai/p/9873169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!