账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    v-model="scope.row.user"怎么获取去watch?
    • 2020-01-01 00:00
    • 10
    31
    0

    <el-table

        :data="tableData"  
        class="tb-edit" 
        style="width: 100%;" 
        border 
        highlight-current-row        
        @row-click="handleCurrentChange"
        >
    
        <el-table-column label="Id" prop="id" width="80" align="center"></el-table-column>
    
        <el-table-column label="User" prop="user" width="160" align="center">
           <template slot-scope="scope">
            <el-input 
              type="text" 
              :id="scope.row.id" 
              :disabled="editId !== scope.row.id"     
              v-model="scope.row.user"
           
            >
            <!-- v-model="scope.row.user" -->
            <!-- <span>{{row.user}}</span> -->
            </el-input>
          </template>
        </el-table-column>
        </el-table>
        export default {
    data() {
      return {             
        button_add: true,
        // userData:[]
        // preForm: JSON.parse(JSON.stringify(this.tableData)), //深拷贝对象
        user: {
          user: '',
          // num: ''
        }
      }
    },
    watch: {
      'scope.row.user':{
        handler(newValue, oldValue){
          // var that = this;
          console.log(newValue, oldValue)
          for(let i in this.tableData){
            // debugger
            
            if(newValue[i] !== oldValue[i]) {
            // if(newValue !== oldValue) {
              this.$confirm('There are changes that have not been saved.Do you want to save them?', 'Prompt', {
                confirmButtonText: 'Save',   
                cancelButtonText: 'No',
                type: 'warning',                
              }).then(() => { 
                this.saveEdit(index, row);        
              }).catch(() => {         
                this.editId = '';  //恢复禁用
                // this.editId = row.id;
                this.tableDataAdd();
                this.$message({
                  type: 'info',
                  message: 'Close!',
                });
              });
              // break;
            }
            // else{
              this.editId = row.id;
              let showDiv = document.getElementById(row.id);
              console.log('showDivvvvvvvvvvv',showDiv)
              setTimeout(() => {
                showDiv.focus();
              },0)
            // } 
          }
        },
        deep: true
      }
    },
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • ▍低调dě嫙侓 普通会员 1楼

      在Vue中,如果你使用了v-model,并且你想在数据发生变化时获取去watch,你可以使用v-model的双向数据绑定。这可以通过使用v-model指令的watch属性来实现。

      以下是一个例子:

      ```html

      ```

      在这个例子中,scope.row.user是你要监听的值,而v-model="scope.row.user"则是你的双向数据绑定的源。当scope.row.user的值发生变化时,v-model会自动更新。

      如果你想要在数据发生变化时发送一个通知,你可以使用v-model的watch的change方法。例如:

      ```html

      ```

      然后,你可以使用v-model的change方法来触发一个事件:

      ```html

      ```

      javascript scope.$watch("scope.row.user", function(value) { // 在这里,你可以在value改变时执行一些操作 });

      请注意,v-model的change方法只会在v-model的改变时触发,而不会在v-model的创建或删除时触发。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部