首页 > 其他分享 >Vue(3)-关于文本框数据框默认值效果(v-blid),数据类型注意

Vue(3)-关于文本框数据框默认值效果(v-blid),数据类型注意

时间:2022-09-07 22:44:59浏览次数:69  
标签:Vue blid 数据类型 score4 score5 score1 score2 默认值

直接看代码,v-blid的使用,数据类型的转换

示例代码

点击查看代码

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<title>avgScore</title>
    		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
    	</head>
    <body>
    	<div id="app">
    		score1:<input type="text" v-model.number="score1" />
    		<br />
    		score2:<input type="text" v-model.number="score2" />
    		<br />
    		score3:<input type="text" v-model.number="score3" />
    		<br />
    		score4:<input type="text" v-model.number="score4" />
    		<br />
    		score5:<input type="text" v-model.number="score5" />
    		<br />
    		总分:{{sumScore}}
    		<br />
    		平均分数:{{avgScore}}
    		<br/>
    		<input :value="defaultv" />
    	</div>
    	
    	
    </body>

    <script>

    	var vm = new Vue({
    		el:"#app",
    		
    		data:{
    			ObjectNum:5,
    			score1:"",
    			score2:"",
    			score3:"",
    			score4:"",
    			score5:"",
    			defaultv:'默认'
    		},
    		methods:{

    		},
    		computed:{
    			avgScore:function(){
    				// 准确到小数点后两位
    				return Math.round(this.sumScore/this.ObjectNum).toFixed(2)
    			},
    			sumScore:function(){
    				return this.score1+this.score2+this.score3+this.score4+this.score5				
    			}
    			
    		},
    		
    		

    	})
    	

    </script>

    </html>

界面效果

知识点

  1. v-bind属性绑定 在本次代码中的 :value可以看出他可以直接缩写为 :属性
  2. v-model.number 数据类型定义为数字,弱类型真不好用

标签:Vue,blid,数据类型,score4,score5,score1,score2,默认值
From: https://www.cnblogs.com/wengming/p/16667576.html

相关文章

  • Vue2:父组件传子组件-属性传值
    通过在子组件中用props["属性1","属性2","属性3"]接收父组件的值;语法:exportdefault{props:[],//接收父组件传的属性methods:{},data(){}......
  • Vue2:数据的劫持顺序
    this组件对象有很对属性和方法都是劫持的"别人"的:比如datamethodspropsthis在构建时给this设置成员的时间顺序data>props属性>方法>计算属性>事件中给this添......
  • Java数据类型
    Java数据类型介绍java是一门强类型语言,要求变量的使用要严格符合规定,所有变量都必须先定义后才能使用。分类基本数据类型整数类型:byte范围在-128~127之间short范围......
  • react和vue这两个框架的相同点和不同点?
    相同点:1.都支持服务器端渲染2.都有virtualdom,组件化开发,通过props参数进行父子组件传值,都实现webComponent规范数据3.数据驱动视图4.都有支持native的方案,react的是r......
  • PostgreSQL-数据类型4
    一、range类型范围类型是表示某个元素类型(称为范围的子类型)的一系列值的数据类型。例如,时间戳的范围可用于表示会议室预定的时间范围。在这种情况下,数据类型是tsrange(“t......
  • VUE
    判断list不为空:pawnList!==undefined&&pawnList!==null&&pawnList.length>0找不到vue界面:可能是自动引用的导致,删除import引用前后台实体匹配不上:数据类型不一致l......
  • Vue环境安装
    环境安装直接引用<scriptsrc="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>或者可以下载到本地位置,在手动导入importVuefrom'./vue.js'或是编辑......
  • vue.js3:图片镜像(翻转)并保存([email protected])
    一,js代码:<template><divstyle="background:#ffffff;"id="root"><div><button@click="restore">还原</button><button@click="flipx">水平镜像</button>......
  • python数据类型之字典Dictionary
    1.python字典字典(dictionary)是除列表以外python之中最灵活的内置数据结构类型。列表是有序的对象集合,字典是无序的对象集合。两者之间的区别在于:字典当中的元素是通过......
  • 第 24 题:聊聊 Redux 和 Vuex 的设计思想
    共同点首先两者都是处理全局状态的工具库,大致实现思想都是:全局state保存状态---->dispatch(action)------>reducer(vuex里的mutation)---->生成newState;整个状态为同步......