1. 程式人生 > 實用技巧 >vue彈框修改

vue彈框修改

根據表ID 修改索引:彈框效果實現的程式碼:

<el-table-column label="操作" width="200" align="center">
            <template slot-scope="scope">
              <div>
                
                <el-button
                  size="mini"
                  type="text"
                  @click="open(scope.row.id, 'index')"
>編輯索引</el-button > </div> </template> </el-table-column>

JS methods 中的程式碼:

open(id, type) {
      this.id = id;
      switch (type) {
        case "edit":
          break;
        case "answer":
          
this.dialogAnswer = true; break; case "video": this.dialogAnalysis = true; break; case "index": this.updateQuestionIndexDialog = true; break; } this.add.id = id; },

<el-dialog title="修改索引" :visible.sync="updateQuestionIndexDialog
"
width="250px"> <el-form :model="addOrEdit" :rules="rules" ref="addOrEdit"> <span> <el-form-item > <el-input v-model="add.questionIndex" width="20px"></el-input> </el-form-item> </span> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="updateQuestionIndexDialog = false">取 消</el-button> <el-button type="primary" @click="editQuestionIndex">確 定</el-button> </span> </el-dialog>

data 函式的相關程式碼:

add:{ id:"", questionIndex:"", }, updateQuestionIndexDialog:false, methods 中的程式碼:
editQuestionIndex() {
      let param = {
        id: this.add.id,
        questionIndex: "",
      };
      if (this.add.questionIndex) {
        param.questionIndex = this.add.questionIndex;
      }
      this.updateQuestionIndex(param);

      this.updateQuestionIndexDialog = false;
      this.add.id = "";
      this.add.questionIndex = "";
      
      this.add.videoExplain = "";
    },

    updateQuestionIndex(param) {
      editQuestionIndex(param).then(() => {
        this.$message.success("修改索引成功");
           this.reload();
      });
    },
editQuestionIndex  在
import{ editQuestionIndex, }from"@/api/resource"; 中引入
export function editQuestionIndex(params) {
  return request({
    url: `/document/question/index/{id}`.format(params),
    method: 'patch',
    data: params

  })
}

傳送的請求如下:

Request URL:
http://IP/document/question/index/213262533656737
Request Method:
PATCH

BODY:
{id: "213262533656737", questionIndex: "120"}