2

I have a parent component with two children components that I need data to move between. I can get emitted data from one child (multiselect.vue) to the parent, but cannot get it to then move into the other child component (render.vue). I suspect it has something to with v-model. Below is a simplifed version.

Parent component

<template>
  <div>
    <multiSelect v-model="content" />
    <renderSplashPage :content="render" />
  </div>
</template>

<script>
import multiSelect from '@/utils/multiSelect'
import render from '@/components/Render'

export default {
  components: {
    multiSelect,
    render,
  },
    name: 'somename',
  data(){
    return{
      content: {},
      render: {}
    }
  },
  watch: {
    'content': function(val) {
      this.render = val;
    },
  },
}
</script>

How can I get the emitted data to be 'watched' and 'picked up' by the 'render' component?

2
  • Is multiselect.vue modifying the data in anyway? Is that modified data what you need to pass to render.vue? Commented Oct 8, 2018 at 22:35
  • Are you sure the watch is called? have you logged the value? If the response is YES for both, then you have problems with the fact that vue data objects are not deeply reactive. So you shouldn't change the reference of an object like that . Commented Oct 8, 2018 at 22:36

1 Answer 1

3

render is a reserved name (i.e., the internal render function cannot be overwritten), and for some reason, Vue silently ignores attempts to modify it.

Rename your property (e.g., to "myRender"), and you should see reactivity. If myRender is always equal to content, you could actually just replace it with content in your binding:

<multiselect v-model="content" :options="options" />
<render :content="content" />

demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.