首页IT科技vue warn $attrs is readonly(Vue warn]: Component is missing template or render function.)

vue warn $attrs is readonly(Vue warn]: Component is missing template or render function.)

时间2025-06-20 04:48:01分类IT科技浏览5200
导读:警告:Component is missing template or render function....

警告:Component is missing template or render function.

问题声明:

组件缺少模板或渲染功能              。

解决问题

方式一:

在写vue项目时              ,网页没有加载出来东西一片空白                    ,然后控制台出现黄色的警告:

原因是:在引入模块的时候没有写后缀!!!

加上.vue后就可以正常显示了                    。

原因:

其实按道理       ,webpack的规则是允许 .vue .js 文件在引入的时候省略文件名后缀的       。

import test from ‘./test.vue’

import test from ‘./test’ //等同于

import test from ‘./test.js’

import test from ‘./test’ //等同于

但是当目录下同事存在 test.js 和 test.vue 文件的时候       ,会优先引入 .js 文件(js>vue)       。

方式二:

新创建的vue文件                    ,没有写模板              ,里面没写任何东西

这个时候也会出来警告

写入模板即可 <template> <div></div> </template> <script lang="ts"> import { defineComponent } from vue export default defineComponent({ setup() { return {} } }) </script> <style scoped></style>

这样问题就解决了

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
vue3.0ui(【vue3-element-admin】Husky + Lint-staged + Commitlint + Commitizen + cz-git 配置 Git 提交规范)