The vue3 element-plus component uses the

The vue3 element-plus component uses the <el-switch> component to report an error. The code is as follows

<el-table-column label="启用">
      <template slot-scope="scope">
        <el-switch
            v-model="scope.row.enable"
            class="ml-2"
            style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
            @change="changeEnable(scope.row)"
        />
      </template>
    </el-table-column>

The error message is as follows:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'row')

 Modify the code as follows:

 <el-table-column label="启用">
      <template v-slot="scope">
        <el-switch
            v-model="scope.row.enable"
            class="ml-2"
            style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
            @change="changeEnable(scope.row)"
        />
      </template>
    </el-table-column>

Change slot-scope="scope" to v-slot="scope" and the problem is solved

Guess you like

Origin blog.csdn.net/wangluoxiehui/article/details/125804791
Recommended