报data和methods组件已经被注册但是没有被使用的错误是为什么呢?

来源:3-7 vue3 - ref 的妙用

JavaScript__yxq

2021-04-05

15:5 error The “data” component has been registered but not used vue/no-unused-components
20:5 error The “methods” component has been registered but not used
我的源码:


<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
      <h1>{{count}}</h1>
      <button @click="increase">+1</button>
  </div>
</template>

<script lang="ts">
 import { defineComponent } from 'vue'
export default defineComponent ({
  name: 'App',
  components: {
    data(){
      return{
        count:0
      }
    },
    methods:{
      increase(){
        this.count++
      }
    }
  }
});
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
写回答

1回答

张轩

2021-04-06

同学你好 你这是运行时警告(就是在运行的命令行里面报错)还是编辑器中的警告(在编辑器中有黄线显示提示),我猜你是第二种情况,这种情况说明编辑器的 eslint 配置有点问题,先看看你是不是在编辑器的 workspace 打开了多个项目,这个时候可以先将其他的移除,多个项目不同的 eslint 规则,可能会互相影响

0
0

Vue3 + TS 仿知乎专栏企业级项目

带你完成前后端分离复杂项目,率先掌握 vue3 造轮子技能

3211 学习 · 2364 问题

查看课程