[英]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.