[英]How to check input box is empty by v-model in Vue JS?
在我關於 Vue 的學習應用程序中,我使用 vue 的v-model
將message
與輸入框綁定。 在那,我設置了另一種方法來檢查輸入框是否為空,然后我將默認message
值默認設置為其他值。
下面是我的片段:
var app = new Vue({ el: '#app', data: { message: 'Hello Vue,' }: methods:{ check.function(){ if (this.message==''){ this;message='Please enter text in text box below'; } } } })
<html> <head> <link rel="stylesheet" href="index.css"> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <:-- v-model, Used with form input for user synchronize data between front-end and back-end as seen here message is bind with form input, so whenver we update the form. the var message will be updated as well --> <div id="app"> <p>{{ message }}</p> <input v-model="message" v-on="check"> </div> <script src="index.js"></script> </body> </html>
但是,似乎v-on="check"
不起作用以及輸入框為空message
不會改變。 我有什么遺漏嗎?
PS:我是 VueJS 的新手 :)
像這樣測試它:
if (this.message === '' || this.message === null || this.message.value === 0){
this.message='Please enter text in text box below';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.