记录项目中遇到的问题

71 阅读1分钟

element table中一个单元格支持添加多个input

image.png

<el-table-column>
    <template #default="{row}">
        <div v-for="(item, index) in row.tagAskFor" :key="index">
            <el-input style="width: 100px" type="textarea" :row="1" v-model="item.content"> </el-input>
         </div>
     </template>
</el-table-column>

vue3 拿到后台返回的对象或数组数据,直接赋值给reactive定义的数组或对象报错

const arr = reactive([])
arr = [1, 2] // 不支持该方式赋值
// 解决方法:
// 1、外面包裹一层
const data = reactive({
    arr: []
})
data.arr = [1, 2]
// 2、使用push
const arr = reactive([])
arr.push(...[1, 2])
// 3、使用ref
const arr = ref([])
arr.value = [1, 2]

const obj = reactive({})
obj = {a:1} // 不支持该方式赋值
// 解决方法:
// 1、外面包裹一层
const data = reactive({
    obj: {}
})
const data.obj = {a:1}
// 2、使用ref
const obj = ref({})
obj.value =  {a:1}
// 3、遍历对象
const obj = reactive({})
const newObj =  {a:1}
for(let key in newObj ){
    obj[key] = newObj[key]
}