zoukankan      html  css  js  c++  java
  • 解决vue项目eslint校验 Do not use 'new' for side effects 的两种方法

    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

  • 相关阅读:
    php投票系统
    php登陆和注册
    php常见报错
    session和cookie的区别
    php加密方法有哪些
    链接数据库封装类
    php数据库批量删除
    三傻大闹宝莱坞
    巴霍巴利王
    布拉德的中年危机
  • 原文地址:https://www.cnblogs.com/xinzaimengzai/p/9873169.html
Copyright © 2011-2022 走看看