Javascript Vue.JS-TypeError:无法使用';在';操作员搜索';未定义';在拉威尔物体中
我想将一个对象从Laravel传递到Vue.js,然后在Javascript Vue.JS-TypeError:无法使用';在';操作员搜索';未定义';在拉威尔物体中,javascript,php,laravel,vue.js,Javascript,Php,Laravel,Vue.js,我想将一个对象从Laravel传递到Vue.js,然后在:v-for=“option in this.options”中使用它。我可以将对象从我的Laravel blade传递到Vue.js组件,并在控制台中显示它,但当我想在v-for中使用该对象时,我会出现以下错误: TypeError: Cannot use 'in' operator to search for 'undefined' in [{"id":1,"poll_id":1,"content":"Black","created_a
:v-for=“option in this.options”
中使用它。我可以将对象从我的Laravel blade传递到Vue.js组件,并在控制台中显示它,但当我想在v-for
中使用该对象时,我会出现以下错误:
TypeError: Cannot use 'in' operator to search for 'undefined' in [{"id":1,"poll_id":1,"content":"Black","created_at":"2019-12-15 02:53:52","updated_at":"2019-12-15 02:53:52"},{"id":2,"poll_id":1,"content":"Blue","created_at":"2019-12-15 02:53:52","updated_at":"2019-12-15 02:53:52"}]
at Proxy.render (app.js:48972)
at VueComponent.Vue._render (app.js:52735)
at VueComponent.updateComponent (app.js:53251)
at Watcher.get (app.js:53662)
at new Watcher (app.js:53651)
at mountComponent (app.js:53258)
at VueComponent../node_modules/vue/dist/vue.common.dev.js.Vue.$mount (app.js:58228)
at VueComponent../node_modules/vue/dist/vue.common.dev.js.Vue.$mount (app.js:61113)
at init (app.js:52315)
at createComponent (app.js:55157)
Vue.JS组件
<template>
<div :v-for="option in this.options">
<div v-if="option" class="option mt-4">
{{ option }}
</div>
</div>
</template>
<script>
export default {
props: [
'id', 'options'
],
mounted() {
this.options = JSON.parse(this.options);
console.log(this.options);
},
}
</script>
这一块有几个错误:
<div :v-for="option in this.options">
<div v-if="option" class="option mt-4">
{{ option }}
</div>
</div>
{{option}}
您必须修复以下问题:
- 将
更改为仅:v-for
v-for
- 从
这个选项中删除
因为你只需要 在这个。
区域中使用script
this.
- 将整个块放在另一个
中,因为
标记中应该只有一个元素。因此,由于使用循环,将渲染多个元素
(2) [{…}, {…}, __ob__: Observer]
0: {…} // id, poll_id, content, created_at, updated_at
1: {…} // id, poll_id, content, created_at, updated_at
length: 2
__ob__: Observer {value: Array(2), dep: Dep, vmCount: 0}
__proto__: Array
<div :v-for="option in this.options">
<div v-if="option" class="option mt-4">
{{ option }}
</div>
</div>