我在用vue-cli。我尝试将aframe直接添加到index.html文件中,并将其导入到我的顶级main.js文件中。我只是不能让Vue识别aframe元素。
我在文件里漏掉了什么样板吗?
警告示例:
vue.runtime.esm.js:619 Vue警告:未知的自定义元素:-您正确注册了组件吗?对于递归组件,请确保提供"name“选项。
发布于 2021-07-14 11:57:09
可以将aframe添加到package.json中的dependencies中。
"browserify-css": "*", // required by aframe
"envify": "*", // required by aframe
"aframe": "^1.2.0", // aframe将aframe添加到已编译的包中:
var Vue = require('vue')
var App = require('./app.vue')
require('aframe')
new Vue({
el: '#app',
render: function (createElement) {
return createElement(App)
}
})并使用<template>中的元素
<template>
<div>
<a-scene>
<a-cylinder color="#FFC65D"></a-cylinder>
</a-scene>
</div>
</template>在这个小故障中查看它
发布于 2021-07-17 11:07:26
Vue 2
为了消除警告,我建议使用放置在Vue.config.ignoredElements中的main.js添加一个组件数组,如下所示:
Vue.config.ignoredElements = [
'a-scene',
'a-camera',
'a-box'
'a-image',
]有关组件的完整列表,请查看这个Repo:框架-组件-列表
我建议使用Vue.config.ignoredElements,而不是像普通Vue组件那样注册A帧组件,因为它们不是Vue组件。
编辑- Vue 3:
在Vue 3中,Vue.config.ignoredElements In main.js不能工作。
相反,在vue.config.js文件中添加以下代码:
// vue.config.js
module.exports = {
chainWebpack: config => {
config.module
.rule('vue')
.use('vue-loader')
.tap(options => {
options.compilerOptions = {
...options.compilerOptions,
isCustomElement: tag => tag.startsWith('a-')
}
return options
})
}
} 这应该包括以'a-‘开头的自定义元素。
https://stackoverflow.com/questions/68349748
复制相似问题