2021-07-23

vue中v-model修饰符的使用和组件使用v-model

1.lazy 修饰器

lazy修饰器在input框中的表现效果是:当你失去焦点后值才会跟新。它的跟新时机是失去焦点后这个修饰器在项目中运用的场景较少
<template> <div>  <input type="text" v-model.lazy="numberCont">  <p>{{numberCont }}</p> </div></template><script> export default {  data(){   return{    numberCont:1,   }  } }</script><style lang="scss" scoped>.input-demo{ height: 40px; width: 300px; border-radius: 4px; text-indent: 10px;}</style>

2.number 修饰器

number修饰器:正常情况下,你在input框中输入的都是字符串类型。但是添加number修饰器后,可以将你在input框中输入的字符变成数字类型;注意:number修饰器并不可以限制input框中只能够输入数字;你输入汉字。或者其他。它只是将你输入的【字符串类型的数字】类型转换为【数字类型】仅此而已
<template> <div>  <input type="text" v-model.number="numberCont">  <p>{{typeof numberCont }}</p> </div></template><script> export default {  data(){   return{    numberCont:1,   }  } }</script>

3.trim修饰器

去除首尾的空格;但是不能够去除中间的空格。这个还是很常用的
<template> <div>  <input type="text" v-model.trim="numberCont">  <p>=={{numberCont }}==</p> </div></template><script> export default {  data(){   return{    numberCont:'',   }  } }</script>

4.总结

这个三个修饰器lazy、number、trim。个人认为只有trim在开发的项目中使用的频率很高其他两个感觉有点鸡肋。number如果只能够限制用户输入数字的话,感觉还是挺好的。但是却不是这样的

5.组件中使用v-model

其实在vue中v-model不仅可以使用在表单上还可以使用在组件上面可能细心的小伙伴平时都发现我们使用的第三方组件上有v-model一起来看看怎么使用

6.组件使用v-model

<template> <div> <child-com v-model="msg"></child-com> <el-button @click="handerOK" primary>获取值</el-button> </div></template><script>import childCom from "@/components/child-com"export default { name: 'App', data(){ return {  msg:'小甜甜' } }, methods:{ handerOK(){  console.log(this.msg ) }, }, components:{ 'child-com':childCom }}</script><style>input{ height: 40px; width: 300px; border-radius: 4px; text-indent: 10px;}</style>

组件

<template> <div>  <!-- <h2>组件</h2> -->  <input type="text" :value="value" @input="onInput"> </div></template><script>export default { props:['value'],  methods: {  // input框中的值变化时,就会执行 onInput 事件  onInput(e){   // 想外传递的事件input是不变的,注意一下   this.$emit('input',e.target.value)  } },}</script>

7.如何需要绑定多个值咋办

<template> <div> =========子组件======= <child-com v-model="msg" :name.sync="name"></child-com> <el-button @click="handerOK" primary>获取值</el-button> <el-button @click="handerother" primary>获取值</el-button> </div></template><script>import childCom from "@/components/child-com"export default { name: 'App', data(){ return {  msg:'小甜甜',  name:'皮卡丘' } }, methods:{ handerOK(){  console.log(this.msg ) }, handerother(){  console.log(this.name ) }, }, components:{ 'child-com':childCom }}</script>

子组件

<template> <div>  <input type="text" :value="value" @input="onInput">  <input type="text" :value="name" @input="otherInput"> </div></template><script>export default { props:['value','name'], methods: {  // input框中的值变化时,就会执行 onInput 事......

原文转载:http://www.shaoqun.com/a/893242.html

跨境电商:https://www.ikjzd.com/

tchibo:https://www.ikjzd.com/w/1928

c2c:https://www.ikjzd.com/w/1576

promoted:https://www.ikjzd.com/w/971


1.lazy修饰器lazy修饰器在input框中的表现效果是:当你失去焦点后值才会跟新。它的跟新时机是失去焦点后这个修饰器在项目中运用的场景较少<template><div><inputtype="text"v-model.lazy="numberCont"><p>{{numberCont}}</p>
c88是什么:https://www.ikjzd.com/w/1017.html
万佛湖门票_安徽六安万佛湖门票价格_多少钱 :http://www.30bags.com/a/411702.html
万国建筑博览群,充斥各种"之最",烂泥塘飞出个金凤凰_上海:http://www.30bags.com/a/220112.html
万豪国际成功举办旅享美食3.0活动,郑州尽展魅力风采:http://www.30bags.com/a/425920.html
万豪国际集团旗下八个奢华酒店品牌 重新定义高端酒店行业格局:http://www.30bags.com/a/434472.html
男人和女人一边摸一边脱 边摸边吃奶边做下面:http://lady.shaoqun.com/a/248136.html
被两个男人咬住吃奶野战 一边亲一边扎下面很爽:http://lady.shaoqun.com/a/248384.html
校花好紧太爽再快点 把校花的腿扛在肩上疯狂输出:http://www.30bags.com/m/a/249881.html
柯奂如再次揭露钮承泽强迫她去床上玩耍。细节的规模令人震惊:http://lady.shaoqun.com/a/429432.html
他的妻子在黑暗中痛苦地呻吟着,他听不见她说话:http://lady.shaoqun.com/a/429433.html
最能触动她心弦的几件事,只要你做到了,她就会死心塌地的找你:http://lady.shaoqun.com/a/429434.html
对大学生男女比例逐年失衡的思考:http://lady.shaoqun.com/a/429435.html

No comments:

Post a Comment