我正试图让aframe和vuejs能够很好地协同工作,但是控制台正在返回警告消息。我猜这是因为aframe在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
代码如下:
应用程序.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>
测试组件.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>
主.js
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
最佳答案
使用简单设置的工作代码:
(Vuejs 2.4.4+框架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)
}
})
小的交互式演示,我以同样的方式构建:
https://rawgit.com/frederic-schwarz/aframe-vuejs-3dio/master/index.html
https://github.com/frederic-schwarz/aframe-vuejs-3dio/blob/master/index.html