简体   繁体   English

Vue.js 错误“app' is assigned a value but never used no-unused-vars

[英]Vue.js error "app' is assigned a value but never used no-unused-vars

**"10:7 error 'app' is assigned a value but never used no-unused-vars" I know there is some similar question due this. **“10:7 error 'app' is assigned a value but never used no-unused-vars” 我知道由于这个原因有一些类似的问题。 But I dont know why my code doesnt work at all.但我不知道为什么我的代码根本不起作用。

So the error is at the main.js file line 10. I thought I'm using my "app" with el:'app' or in export fault with 'app'所以错误出现在 main.js 文件的第 10 行。我以为我正在使用带有 el:'app' 的“应用程序”或使用“应用程序”的导出错误

I have 2 files我有 2 个文件

**App.vue:****






    <template>
      <div id="app" v-cloack>
        <img src="./assets/999.jpg">
        <h1>{{ msg }}</h1>
        <ul>
          <input type="file" ref="myFile" @change="selectedFile"><br/>
          <textarea v-model="text"></textarea>
      </div>
    </template>


    <script>
    //import HelloWorld from './components/HelloWorld';
    //import main from './main.js';
    export default {
      name: 'app',
      data: ()=> {
        //
          return{
              msg: 'Datei uploaden'

          }
      },
    }
    </script>

    <style>

    </style>'''





**main.js:**




    import Vue from 'vue'
    import App from './App.vue'
    import vuetify from './plugins/vuetify';

    Vue.config.productionTip = false
    Vue.config.devtools = false;
    export default {
      name: 'app',
      data: ()=> {
      var app;
      app =new Vue({

    el: '#app',
    vuetify,
    render: h => h(App),
    data: {
      text:''
    },

    methods:{
        selectedFile() {
          console.log('selected a file');
          console.log(this.$refs.myFile.files[0]);

          let file = this.$refs.myFile.files[0];
          if(!file || file.type !== 'text/plain') return;

          // Credit: https://stackoverflow.com/a/754398/52160
          let reader = new FileReader();
          reader.readAsText(file, "UTF-8");
          reader.onload =  evt => {
            this.text = evt.target.result;
          }
          reader.onerror = evt => {
            console.error(evt);
          }

        }
    }
  })
  }
}
//.$mount('#app')

I really struggle since a few days.几天以来,我真的很挣扎。 I would be very happy if anybody can help Thanks如果有人可以提供帮助,我会很高兴谢谢

You can add /* exported variableName */ to ignore the eslint since you are using app variable outside your file您可以添加/* exported variableName */以忽略 eslint,因为您在文件外部使用 app 变量

so above your app variable add /* exported app */所以在你的应用变量上面添加/* exported app */

to read more https://eslint.org/docs/rules/no-unused-vars阅读更多https://eslint.org/docs/rules/no-unused-vars

Change main.js to this code将 main.js 更改为此代码

import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify';

Vue.config.productionTip = false;
Vue.config.devtools = false;

var app = new Vue({
    el: '#app',
    vuetify,
    render: h => h(App),
    data: {
        text: ''
    },
    methods: {
        selectedFile() {
            console.log('selected a file');
            console.log(this.$refs.myFile.files[0]);

            let file = this.$refs.myFile.files[0];
            if (!file || file.type !== 'text/plain') return;

            // Credit: https://stackoverflow.com/a/754398/52160
            let reader = new FileReader();
            reader.readAsText(file, "UTF-8");
            reader.onload = evt => {
                this.text = evt.target.result;
            }
            reader.onerror = evt => {
                console.error(evt);
            }

        }
    }
})

export default app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反应错误“ ./src/App.js第7行:&#39;APIKEY&#39;被分配了一个值,但从未使用过no-unused-vars” - React error “./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars” 11:5 错误“路由器”被分配了一个值,但从未使用过 no-unused-vars - 11:5 error 'router' is assigned a value but never used no-unused-vars &#39;inStock&#39; 被赋值但从未使用过 no-unused-vars - 'inStock' is assigned a value but never used no-unused-vars react.js 'x' 被分配了一个值,但从未使用过 no-unused-vars - react.js 'x' is assigned a value but never used no-unused-vars Vue.js 编译错误:no-unused-vars &amp; no-undef - Vue.js Compile Error: no-unused-vars & no-undef Eslint with Vue 给出 function 已定义但从未使用过 no-unused-vars - Eslint with Vue gives function is defined but never used no-unused-vars 组件已定义但从未使用 reactjs 中的 no-unused-vars 错误警告 - component is defined but never used no-unused-vars error warning in reactjs src\\App.js &#39;nav&#39; 已定义但从未使用过 no-unused-vars - src\App.js 'nav' is defined but never used no-unused-vars 定义了“ stringValues”,但从未使用过no-unused-vars - “stringValues” is defined but never used no-unused-vars 定义了“标头”,但从未使用过未使用的变量 - 'Header' is defined but never used no-unused-vars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM