[Vuejs]-How change child component v-model value in parent component correctly?

0👍

I guess you are binding this ‘sinput’ on selected tree node value, then you’ll need to use event ‘node-click’ on tree component.

For v-model on customizing component, you need ‘model’ option in vue.

ref: Vue.js – Customizing Component v-model

here’s some code, hope it would help 🙂

<template>
 <el-tree
   ...
   @node-click="handleNodeClick"
 />
</template>
export default {
  model: {
    prop: 'sinput',
    event: 'change'
  },
  props: {
    sinput: String
  },
  methods: {
    handleNodeClick(data) {
      if (!data.children) {
        // your code
        this.$emit('change', data.value);
      }
    }
  }
}

Leave a comment