由于不能直接修改props的传递的变量,故使用$emit

<template>
    <view>
        <input ref='input1' type="text" placeholder="请输入" @input="inputChange" />
    </view>
</template>

<script>
    export default {
        props: ['transVal'],
        data() {
            return {
            };
        },
        watch: {
            transVal(val) {
                (this.$refs.input1.valueSync!= val) && (this.$refs.input1.valueSync = val)
            }
        },
        methods: {
            inputChange(e) {
                this.$emit('changeVal', e.detail.value)
            }
        }
    }
</script>

<style>

</style>

调用:<private-input :transVal="inputVal" @changeVal="inputVal=$event"></private-input>

 

相关文章:

  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
相关资源
相似解决方案