我试图让Aframe和vuejs相互配合,但是控制台正在返回警告消息。我猜测这是因为在vue有机会更改属性值之前会检查属性值。
警告讯息
core:schema:warn Unknown property `color` for component/system `undefined`. +349ms 2aframe.js:327
core:schema:warn Unknown property `color` for component/system `undefined`. +2ms aframe.js:327
core:schema:warn Unknown property `color` for component/system `undefined`. +1ms aframe.js:327
core:schema:warn Unknown property `height` for component/system `undefined`. +1ms aframe.js:327
core:schema:warn Unknown property `color` for component/system `undefined`. +1s aframe.js:327
以下是代码:
App.vue
<template>
<a-scene>
<test-component v-for="block in blocks" :color="block.color" :position="block.pos"></test-component>
<a-box :color="color" height="4"></a-box>
<a-entity position="0 0 10" camera look-controls></a-entity>
</a-scene>
</template>
<script>
import TestComponent from './TestComponent.vue';
require('aframe');
export default {
name: 'app',
components:{
TestComponent,
},
data(){
return {
color: 'green',
blocks: [
{color: 'red', pos: "1 0 0"},
{color: 'orange', pos: "2 0 0"},
{color: 'yellow', pos: "3 0 0"}
]
}
},
mounted(){
//test to see if a-frame updates properly
let that = this;
setTimeout(function(){
that.blocks.push({color: 'lime', pos: "4 0 0"})
}, 1000)
setTimeout(function(){
that.blocks[3].pos = "5 0 0"
}, 2000)
}
}
</script>
TestComponent.vue
<template lang="html">
<a-box :color="color" :position="position"></a-box>
</template>
<script>
export default {
props: ['color','position'],
}
</script>
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>aframetest</title>
</head>
<body>
<div id="app"></div>
<script src="dist/build.js"></script>
</body>
</html>
main.js
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
答案 0 :(得分:0)
工作代码,设置更简单:
(vuejs 2.4.4 + aframe 0.6.1)
https://jsfiddle.net/jg6uhh21/
HTML:
<a-scene id="app">
<test-component v-for="block in blocks" :color="block.color" :position="block.pos"></test-component>
<a-entity position="0 0 10" camera look-controls></a-entity>
</a-scene>
的javascript:
Vue.component('test-component', {
props: ['color','position'],
template: `<a-box :color="color" :position="position"></a-box>`
})
new Vue({
el: '#app',
data(){
return {
blocks: [
{color: 'red', pos: "1 0 0"},
{color: 'orange', pos: "2 0 0"},
{color: 'yellow', pos: "3 0 0"}
]
}
},
mounted(){
setTimeout(() => {
this.blocks.push({color: 'lime', pos: "4 0 0"})
}, 1000)
setTimeout(() =>{
this.blocks[3].pos = "5 0 0"
}, 2000)
}
})
小型互动演示我以相同的方式组合了vue.js和aframe:
https://rawgit.com/frederic-schwarz/aframe-vuejs-3dio/master/index.html
https://github.com/frederic-schwarz/aframe-vuejs-3dio/blob/master/index.html
答案 1 :(得分:0)
我一直在寻找相同问题的答案,所以我在GitHub上demo上进行游戏
我缺少的部分是
Vue.config.ignoredElements = [
'a-scene',
'a-entity',
'a-camera',
'a-box'
]
我对Vue有点陌生,我不知道Vue.config.ignoredElements
存在。我将其添加到main.js中,并添加了我正在使用的所有aframe原语。