问题描述:约会时间 根据 航班动态中的数据进行初始化,当用户修改了约会时间后,再次加载订单信息时,约会时间又被初始化掉了;
解决方法:在组件中增加变量:input=”inputValue”,并在props 中定义这个变量;
在created() {
       this.$watchAsObservable(‘change_key’) 方法中,判断这个变量 进而确定是否要 根据监控的数据初始化值;
组件代码如下:window.vapp_startTime = new Vue({el: '#startTime',template: ``<br />type="datetime":class="isAdd ? 'inputbg' : 'c2'":input="inputValue"v-model="value"></DatePicker>,`<br />`   data() {`<br />`       return {`<br />`           value: moment().format("YYYY-MM-DD HH:mm:ss"),`<br />`           item: window.vapp_fltplan.item`<br />`       }`<br />`   },`<br />`   props: {`<br />`       inputValue: String,`<br />`   },`<br />`   computed: {`<br />`       change_key() {`<br />`           let time = this.item.TRIPTYPE == "1" ? this.item.ARRTIME : this.item.DEPTIME;`<br />`           const mtime = moment(this.item.FLTDATE + " " + time, "YYYY-MM-DD HH:mm")`<br />`           if (this.item.TRIPTYPE == "1") {`<br />`               if (this.item.CHANNELTYPE == "1") {`<br />`                   return mtime.subtract(0.5, "hours");`<br />`               } else {`<br />`                   return mtime.subtract(45, "minutes");`<br />`               }`<br />`           }`<br />`           else {`<br />`               if (this.item.CHANNELTYPE == "1") {`<br />`                   return mtime.subtract(1.5, "hours");`<br />`               } else {`<br />`                   return mtime.subtract(2, "hours");`<br />`               }`<br />`           }`<br />`       },`<br />`       isAdd() {`<br />`           let time = this.item.TRIPTYPE == "1" ? this.item.ARRTIME : this.item.DEPTIME;`<br />`           const mtime = moment(this.item.FLTDATE + " " + time, "YYYY-MM-DD HH:mm").format('YYYY-MM-DD HH:mm:ss');`<br />`           return moment(mtime).format('YYYY-MM-DD') != moment(this.value).format('YYYY-MM-DD');`<br />`       }`<br />`   },`<br />`   created() {`<br />`       this.$watchAsObservable('change_key')`<br />`           //.debounceTime(1e3)  //防抖动`<br />`           .subscribe(({ newValue, oldValue }) => {`<br />`               //if (this.value == null)`<br />`               //console.log("传递过来的变量:this.inputValue =", this.inputValue);`<br />`               if (!this.inputValue)//根据变量值判断是否根据监控组件初始化数据<br />                   this.value = newValue.format(‘YYYY-MM-DD HH:mm:ss’);<br />           });<br />   },<br />   //watch: {<br />   //    value(newVal, oldVal) {<br />   //        debugger;<br />   //        console.log(newVal, oldVal);<br />   //    }<br />   //}<br />   <br />})`
调用处代码如下:
if (window.vapp_startTime != null) {
                   if (rsv[“STARTTIME”] != window.vapp_startTime.value) {
                       window.vapp_startTime.inputValue = “1”; //设置变量值
                       window.vapp_startTime.value = moment(rsv[“STARTTIME”]).format(“YYYY-MM-DD HH:mm:ss”);
                   }
               }
