有没有办法在同一个组件中观看不同的v模型?

时间:2016-10-30 16:02:15

标签: vue.js

我不知道该怎么做,但我有一个组件,我在两个不同的地方使用,这个组件有一个<input v-model="model" >。 我在我的组件中看到这个v模型; 问题是模型的变化;在一个地方我有model = array.val1,在第二个我有model = array.val2 当model = array.val1时我想做某事,当model = array.val2时我想做一些不同的事情 它就像我想在模型上做一个条件,如果它等于做其他事做这个

这是我的组件

Vue.component('boisson-view', {
props: ["boiss", "model","type","name"],
template: `
    <div class="radio">
        <label> 
        <input :type="type" :name="name" v-model="model" :value="boiss.id" > 
            {{boiss.name}} 
            <img :src="boiss.link" :id="boiss.id" style="display:none;position: fixed;">
        </label>
    </div>`,
created:function(){
    this.setboisson = vm.setboisson;
},
watch: {

    'model': { handler : function(val) {
        // this will get triggered within boisson-view component, when one of your "o" changes
        if(val !== null )
        this.ord.is_menu = true;
        else
        this.ord.is_menu = false;

        console.log(JSON.stringify(val));

        },deep:true
    },

}

所以当我重用组件

时,我不想对该模型做同样的事情

1 个答案:

答案 0 :(得分:1)

您可以多次重复使用该组件,您可以通过手表model中的条件处理此问题

if(model === array.val1) {
   // do something
}

if(model === array.val2) {
  //do another thing
}
相关问题