• vue数据数据双向绑定


    数据双向绑定

    主要涉及以下内容

    v-model,number和v-model.lazy

    <!DOCTYPE html>
    <html lang="zh">
    
    <head>
    	<meta charset="UTF-8">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<script src="./js/v3.2.8/vue.global.prod.js"></script>
    	<title>Document</title>
    </head>
    
    <body>
    	<!--  -->
    	<div id="app">
    		<h1 v-bind:title="tit" v-text="msg" v-on:click="showdata"></h1>
    		<button v-on:click="jianshao">-</button>
    		<span v-text="num">0</span>
    		<button v-on:click="zengjia">+</button>
    		<button @click="qietu(1)">切换图片1</button>
    		<button @click="qietu(2)">切图3</button>
    		<img v-bind:src="mapsrc" alt="图片" style="100px;height: 100px;">
    		<ul>
    			<li v-for="item in lists">{{item}}</li>
    		</ul>
    		<button v-for="item,index in mapslist" @click="qietu(index)">{{index+1}}</button>
    		<hr>
    		<form v-on:submit.prevent="post">
    			<input type="text" v-model="msg">
    			<button>提交</button>
    		</form>
    	</div>
    	<script>
    		// 如何操作文本、属性、事件
    		Vue.createApp({
    			data() {
    				return {
    					msg: "数据双向绑定",
    					tit: "文本绑定",
    					num: "0",
    					mapsrc: "/sitefiles/assets/images/video-clip.png",
    					mapslist: [
    						"/sitefiles/assets/images/audio-clip.png",
    						"/sitefiles/assets/images/default_avatar.png",
    						"/sitefiles/assets/images/loading.gif"
    					],
    					lists: ["qqqq", "22222", "哈哈", "4"]
    				}
    			},
    			methods: {
    				showdata() {
    					alert("操作事件")
    				},
    				zengjia() {
    					this.num++;
    				},
    				jianshao() {
    					if (this.num > 0) {
    						this.num--;
    					}
    				},
    				qietu(i) {
    					this.mapsrc = this.mapslist[i];
    				},
    				post() {
    					console.log("控制台console输出");
    					console.log(this.msg);
    				}
    			}
    		}).mount("#app")
    	</script>
    
    </body>
    
    </html>
    

      双向数据绑定涉及输入相关属性

    input失去焦点 v-model-lazy=""

    v-model.number限制数字

    v-model.trim清除字符空格

  • 相关阅读:
    [POJ 1200]Crazy Search
    [来源不详]删数方案数
    noip搜索模拟题 骰子
    [SDOI2010]地精部落
    [HAOI2008]硬币购物
    BZOJ1009: [HNOI2008]GT考试
    BZOJ1830: [AHOI2008]Y型项链 & BZOJ1789: [Ahoi2008]Necklace Y型项链
    BZOJ1251: 序列终结者
    BZOJ3620: 似乎在梦中见过的样子
    BZOJ4477: [Jsoi2015]字符串树
  • 原文地址:https://www.cnblogs.com/xiongwei/p/16609178.html
Copyright © 2020-2023  润新知