I'm trying to include a component with v-for
. The data source infoTexts
is an Object containing the locale code as a key and the message as value.
Example:
{
nl: 'Text in Dutch',
fr: 'Text in French',
en: 'Text in English'
}
Below is my code that I use to include the components:
<text-editor v-for="(value, index) in infoTexts" :key="index" :database-message-contents="value" :message-locale-code="index"></text-editor>
Both database-message-contents
and message-locale-code
are props on the text-editor
component.
I don't receive any error message in my console, but the text-editor
is not showing up.
The issue involved a misunderstanding with the life cycle of Vue.
I was creating the infoTexts
in the mounted
method. Relocating it to the created
method solved the issue.
Your own answer to your problem ist only partially true and can mislead other users.
Let me explain why:
Assumed code in your mounted
method:
this.infoTexts.nl = 'Text in Dutch'
This code does not work because Vue cannot detect properties added to objects at runtime.
What you should be doing instead is using the Vue.set method provided. So your new code would look something like this.
Vue.set(this.infoTexts, 'nl', 'Text in Dutch');
Using the code above you can add new languages whenever you want and in whatever lifecycle method you want.
Even if you didn't provide the code showing the creation of your infoTexts
array this is causing the problem 95% of the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With