vue實戰--一些小問題:code對應的value怎麼更好的解決?時間控件的賦值問題?怎麼知道用戶點擊的是確定還是取消?

1,引用時間控件的時候要記得賦值

<el-date-picker v-model="listQuery.onlineTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                              label-width="10px"
                              placeholder="yyyy-mm-dd 00:00:00" **@change="startTimeStatus"**
                              style="margin-right: 10px;width:300px;float:left;" :disabled="checkCouponDis">
              </el-date-picker>
methods(){
// 時間開始選擇器
    startTimeStatus: function (value) {
      this.listQuery.onlineTime = value
    },
    }

2,你有一個list,裏面有code和code對應的value,後端返給你code,怎麼取到相應的value呢?

 <el-table-column  label="場景" align="center" prop="scene" **:formatter="formatterScene**">
        </el-table-column>
methods(){
	formatterScene(row, column) {
	      if(Array.isArray(this.sceneList) && this.sceneList.length > 0) {
	        for (let sceneObj of this.sceneList) {
	          if (sceneObj.dataCode == row.scene) {
	            return sceneObj.dataValue;
	          }
	        }
	      }
	    },
}

注意:第二段代碼中sceneList就是你已經獲得的list

三:怎麼知道用戶點擊的是確定還是取消?

methods: {
    //保存卡券信息
    getList(){
      this.$confirm('保存後業務線規則不可更改,確定保存嗎?', '提示', {
        confirmButtonText: '確定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        fetchList(this.listQuery).then(response => {
          if (response.code =='2000'){
            this.$message({type: 'success', message: '保存成功!'});
            var saveFlag = "false";
            setSaveFlag(saveFlag)
            this.$router.push("/couponsSystem/couponsManage/couponsList/index");
          }else {
            this.$message({type: 'error', message:response.message});
          }
          setTimeout(() => {
            this.listLoading = false
          }, 2.5 * 1000)
        })//到這是點擊確定後執行的代碼
      }).catch(() => {
      //這裏可以寫點擊取消之後需要執行的代碼
      });
    },
    }

上面這段代碼:點確定的時候纔會執行then後面的代碼,如果點擊取消,執行的是catch(() => {
})
這裏面的代碼,如果你點擊取消之後需要寫一些代碼,可以寫在catch裏面
即總結:點擊確定走then。點擊取消走 catch

注意:如果你想看點的確定還是取消,去獲取這個結果值的話,以下網頁地址有解答:
https://zhidao.baidu.com/question/206131268.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章