Vue3 技巧

396 阅读1分钟

1.promise取值[[PromiseResult]]

从后端获取到数据,想要得到Array
image.png
查阅方法,只有通过.then()来读取

const data = ref()
allData.then((list) => {
    // 处理代码逻辑
    console.log(list)
    // 不建议赋值
    data.value = list //后续访问list,可能为空
    }

注意因为.then()是异步的,不建议在then方法中赋值

2.常用方法

(1)匹配List索引

list.findIndex(item => item.id===id && item.name === name)

3.Math

(1)向上取整Math.ceil

例如:Math.ceil(4.8)=5,Math.ceil(4.1)=5