I am facing an issue in my Vue project while trying to render the data from local JSON. I have read instructions and followed them-- every step-- yet the error prevails. Since I am new to Vue and advanced programming itself, I seek help.
english.json
{
"0": {
"text": "This be a square",
"color": "blue",
"size": "small"
},
"1": {
"text": "here lies a square",
"color": "red",
"size": "medium"
},
"2": {
"text": "Tharr be a squaree",
"color": "black",
"size": "large"
}
}
ExperienceText.vue
<template>
<article class="content__box" :v-for="data in expJson">
{{data.text}}
<h6>{{data.text}}</h6>
<h3>{{data.color}}</h3>
<p>{{data.size}}</p>
</article>
</template>
<script>
import json from "@/components/json/english.json";
export default {
name: "ExperienceText",
data() {
return {
expJson: json
};
}
};
</script>
Error
[Vue warn]: Property or method "data" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <ExperienceText> at src/components/mainComp/subComp/ExperienceText.vue
<ExperienceSection> at src/components/mainComp/ExperienceSection.vue
<Experience> at src/components/mainComp/Experience.vue
<Main> at src/components/Main.vue
<Container> at src/views/Container.vue
<App> at src/App.vue
<Root>
Show 60 more frames
vue.runtime.esm.js?2b0e:619 [Vue warn]: Property or method "data" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <ExperienceText> at src/components/mainComp/subComp/ExperienceText.vue
<ExperienceSection> at src/components/mainComp/ExperienceSection.vue
<Experience> at src/components/mainComp/Experience.vue
<Main> at src/components/Main.vue
<Container> at src/views/Container.vue
<App> at src/App.vue
<Root>
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: Cannot read property 'text' of undefined"
found in
---> <ExperienceText> at src/components/mainComp/subComp/ExperienceText.vue
<ExperienceSection> at src/components/mainComp/ExperienceSection.vue
<Experience> at src/components/mainComp/Experience.vue
<Main> at src/components/Main.vue
<Container> at src/views/Container.vue
<App> at src/App.vue
<Root>
vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read property 'text' of undefined
at Proxy.render (eval at ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"db619a62-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/mainComp/subComp/ExperienceText.vue?vue&type=template&id=088f3b1e& (app.js:1089), <anonymous>:15:36)
at VueComponent.Vue._render (vue.runtime.esm.js?2b0e:3548)
at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4066)
at Watcher.get (vue.runtime.esm.js?2b0e:4479)
at new Watcher (vue.runtime.esm.js?2b0e:4468)
at mountComponent (vue.runtime.esm.js?2b0e:4073)
at VueComponent.Vue.$mount (vue.runtime.esm.js?2b0e:8415)
at init (vue.runtime.esm.js?2b0e:3118)
at createComponent (vue.runtime.esm.js?2b0e:5978)
at createElm (vue.runtime.esm.js?2b0e:5925)
The JSON arrived
In my app, the article tag is not visible at all. I am pretty sure it is because the JSON data is not being rendered properly. How do i fix this issue?
:
in front ofv-for
– Dan:
before v-for, But when I do it in my code I get following issues2:3 error The template root disallows 'v-for' directives vue/valid-template-root 2:3 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key
– Ajaya Bajracharya