小编anu*_*art的帖子

Vue.js单个文件组件“名称”在使用者中不被接受

请原谅我的语法,我是vue.js的新手,可能未正确使用这些术语。

我只有一个名为CreateTodo.vue的文件组件(SFC)。我给它起了名字“ create-todo-item”(在name属性中)。当我将其导入到app.vue文件中时,如果使用标记,则只能使用该组件<create-todo>。如果使用<create-todo-item>,则该组件将不会在页面上呈现。

从那以后,我了解到,如果我将app.vue中的组件以components: { 'create-todo-item': CreateTodo }而不是格式列出,该怎么办components: { CreateTodo }

我的问题是:是否有必要在name属性中为组件命名?它在消费者中没有得到尊重,如果我将其保留为空,则该应用程序运行时不会出错。

另外,我是否相信vue-loader正在基于PascalCase导入语句为模板使用分配kebab-case元素名称?

错误-组件名称属性

这是我尝试命名SFC(CreateTodo.vue)的代码

<script>
  export default {
    name: 'create-todo-item',
    data() {
      return {
        titleText: '',
        projectText: '',
        isCreating: false,
      };
    },
};
</script>
Run Code Online (Sandbox Code Playgroud)

我的App.vue忽略了组件中列出的名称。即使我有元素<create-todo>而不是html,也可以很好地呈现<create-todo-item>

<template>
  <div>
    <!--Render the TodoList component-->
    <!--TodoList becomes-->
    <todo-list v-bind:todos="todos"></todo-list>
    <create-todo v-on:make-todo="addTodo"></create-todo>
  </div>
</template>

<script>
  import TodoList from './components/TodoList.vue'
  import CreateTodo from './components/CreateTodo.vue'

  export default {
    name: 'app', …
Run Code Online (Sandbox Code Playgroud)

single-page-application vue.js

7
推荐指数
1
解决办法
2954
查看次数

标签 统计

single-page-application ×1

vue.js ×1