本文實例講述了vue input實現點擊按鈕文字增刪功能。分享給大家供大家參考,具體如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>www.jb51.net vue點擊按鈕文字增刪</title>
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
</style>
</head>
<body>
<div id="app">
<input type="text" v-model="text">
<button @click="add">add</button>
<button @click="clear">remove</button>
<button @click="clean">remove one</button>
<div v-for="x in arr" class="box">{{x}}</div>
</div>
<div id="app-2">
<span v-bind:title="message">
鼠標懸停幾秒鐘查看此處動態綁定的提示信息!
</span>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
<script>
var app2 = new Vue({
el: '#app-2',
data: {
message: '頁面加載于 ' + new Date().toLocaleString()
}
});
const app=new Vue({
el:"#app",
data:{
arr:[],
text:""
},
methods:{
add(){
this.arr.push(this.text);
},
clear(){
this.arr=[]
},
clean(){
this.arr.pop();
}
}
})
</script>
</html>
這里使用在線HTML/CSS/JavaScript代碼運行工具:http://tools.jb51.net/code/HtmlJsRun測試上述代碼,可得如下運行效果:

希望本文所述對大家vue.js程序設計有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。