Vue.js change placeholder of text input according to v-model value

人走茶凉 提交于 2020-06-11 06:02:08

问题


I need to change placeholder of a text input via Vue.js data binding. Here is my code.

<select2 :options="power_options" v-model="power">
     <option selected value="hp">hp</option>
     <option value="kW">kW</option>
 </select2>

 <input name="power_to" type="text" 
        class="form-control pwer_change" v-model="power_from" placeholder='[[ power ]]' style="display: inline;width: 48%;">

 <input name="power_from" type="text" 
        class="form-control pwer_change" v-model="power_to" placeholder="[[ power ]]" style="display: inline;width: 48%;">

Here is my vue code...

        var vm = new Vue({
            el: '#el',
            delimiters: ["[[", "]]"],
            data: {
                power: "hp",
                power_from: null,
                power_to: null,
            },
            created: function () {

            },
            methods: {
            }
        });

I have changed "{{" delimiters to "[[" and using select2 Wrapper Component. I need to change "power to" and "power from" input placeholders according to v-model="power"


回答1:


You should use placeholder property notation in this case :placeholder="[[ power ]]":

<input
  name="power_to"
  type="text"
  class="form-control pwer_change"
  v-model="power_from"
  :placeholder="[[ power ]]"
  style="display: inline;width: 48%;"
/>


来源:https://stackoverflow.com/questions/53706390/vue-js-change-placeholder-of-text-input-according-to-v-model-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!