【问题标题】:Import composition api导入组合api
【发布时间】:2021-07-15 13:11:56
【问题描述】:

假设我有index.ts

import { defineComponent, onMounted } from '@nuxtjs/composition-api'


const Todo = defineComponent({
  setup() {

    onMounted(() => {
      test()
    })

    function test(){

      return 'test'
    }
  },
  // You need to define an empty head to activate this functionality
  head: {},
})

export default Todo

我有Todo.vue

 <template>
    <p>
      Hello world!
    </p>
</template>

<script lang="ts">
import Todo from './index'
export default Todo
</script>

然后将其导入到其他文件中使用

<template>
  <Todo/>
</template>


<script lang="ts">
import { defineComponent} from '@nuxtjs/composition-api'

import Todo from '../../components/pages/Todo/'

export default defineComponent({
  components: {Todo},
  setup(){}
})

</script>

我收到一条错误消息,提示 render function or template not defined in component: Todo

知道我可以从哪里开始解决这个问题吗?

【问题讨论】:

标签: typescript vue.js nuxt.js


【解决方案1】:

试试看:

<template>
  <h1 class="test">
    Hello world!
  </h1>
</template>

<script lang="ts" src="./index.ts">

</script>

【讨论】:

  • 我怎样才能像export default Todo一样导出组件index.ts,因为我正在使用它到其他目录
  • 你可以在index.ts里面做const Todo=defineComponent({...}); export default Todo
  • @kissu 一定要避免装载机出现任何问题
  • 如何将 Todo.vue 传递给其他 vue 文件,并像 组件一样使用它
  • import Todo from './components/Todo.vue' 然后将其添加到components 选项components:{Todo}
猜你喜欢
  • 2021-10-28
  • 2022-10-04
  • 2021-12-25
  • 1970-01-01
  • 2021-12-15
  • 2020-08-20
  • 1970-01-01
  • 2022-09-28
  • 1970-01-01
相关资源
最近更新 更多