【问题标题】:vuejs2 set value from php to vuejs2 with v-modelvuejs2 使用 v-model 将值从 php 设置为 vuejs2
【发布时间】:2019-05-22 12:33:03
【问题描述】:

嗨,我有这个 html 代码

<input type='text'   :value='{{$poss["pos_discount_value"]}}' v-model='pos_discount_value' />

这是 vuejs2 代码

data:{
    message:'', 
    item_search_array:false,
    arrayresults:[],
    total:0,
    quantity:1,
    discount:0,
    pos_discount_value:0,
},

现在我在 vuejs2 代码中将 pos_discount_value 定义为 0 在我的 html 代码中,它来自数据库作为不同的值 如何将 pos_discount_value 的默认值设置为来自 html 而不是 0 的值,谢谢

【问题讨论】:

    标签: php vue.js vuejs2


    【解决方案1】:

    你也可以在created钩子上使用自定义事件

    <input type='text'  @initDiscount='pos_discount_value={{$poss["pos_discount_value"]}}' v-model='pos_discount_value' />
    
    created: function () {
        this.$emit('initDiscount');
    }
    

    【讨论】:

      【解决方案2】:

      我喜欢这样的

      <input 
        v-model="pos_discount_value"
        :run="!pos_discount_value ? pos_discount_value = {{$poss['pos_discount_value']}} : true"
      />
      

      谢谢大家

      【讨论】:

      • 它看起来更像是作弊:) 狡猾
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2019-07-17
      • 2022-01-09
      • 2018-06-01
      相关资源
      最近更新 更多