我试图让textarea根据条件显示一些文本作为占位符。 activity()
是一个返回对象的计算函数。这个的正确语法是什么?
<textarea
v-model="feedback_text"
placeholder={{ activity.feedback }} ? {{ activity.feedback }} : "Leave some formative feedback"
>
答案 0 :(得分:2)
那怎么样?
<textarea
v-model="feedback_text"
v-bind:placeholder='activity.feedback ? activity.feedback : "Leave some formative feedback"'
></textarea>
演示:
var demo = new Vue({
el: '#demo',
data: {
feedback_text: "",
feedback_check: false
},
computed: {
activity: function () {
return this.feedback_check ? "You have checked that box" : false;
}
}
});
&#13;
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="demo">
<input type="checkbox" id="checkbox" v-model="feedback_check">
<label for="checkbox">Test for computed changes</label>
<textarea
v-model="feedback_text"
v-bind:placeholder='activity ? activity : "Leave some formative feedback"'
></textarea>
</div>
&#13;