1***@qq.com
1***@qq.com
  • 发布:2019-09-20 17:57
  • 更新:2020-09-30 09:04
  • 阅读:2299

uni-number-box 重置为

分类:uni-app

uni-number-box 如何重置

2019-09-20 17:57 负责人:无 分享
已邀请:
1***@163.com

1***@163.com

上面这个方法只能重置当前数据,但是页面渲染的数据还是没有重置,原因是简单的this.numberValue = 0只是重置了当前父组件当中的数据,没有触发子组件。想解决页面渲染需要触发子组件。步骤如下
1、在子组件上添加ref属性:
<uni-number-box ref='numberbox' :value="numberValue" />
注意:ref当中尽量不要使用驼峰命名法,因为调用时不支持,要想使用驼峰命名法需要两个单词之间加-
2、在子组件当中定义reset方法:
reset(){ this.inputValue = 0} 0为需要重置的数据
3、在父组件当中定义重置的方法:
reset(){
this.$refs['numberbox'].reset() // 这里调用子组件的reset方法,用于重置页面上的显示
this.numberValue = 0 //这里是重定义当前data当中的值

  }  
陈晨1

陈晨1

<template>  
  <view class="">  
    <uni-number-box :value="numberValue"  />  
    <text @click="reset">重置</text>  
  </view>  
</template>  

<script>  
  export default {  
    data() {  
      return {  
        numberValue: 0  
      }  
    },  
    methods: {  
      reset(){  
        this.numberValue = 0 //这里定义重置的值  
      }  
    }  
  }  

</script>  
2***@qq.com

2***@qq.com

为啥只能重置一次

该问题目前已经被锁定, 无法添加新回复