1:toRaw方法可以将一个被 reactive 包裹的对象还原为其中的“原始”对象
import { reactive, toRaw } from 'vue'
const state = reactive({
count: 0
})
const rawState = toRaw(state)
console.log(rawState === state)
rawState.count += 1
console.log(state.count)
const params = reactive({
jobGroup: 11,
triggerStatus: triggerStatus.value,
start: start.value,
length: length.value,
});
const getServerData = () => {
axios
.get("/api/xxl-job-admin/jobinfo/pageList", { params: toRaw(params) })
.then((response) => {
let data = response.data;
console.log(data);
console.log("ddd", params.start);
});
};
2:markRaw 方法可以将一个对象标记为“非响应式”,从而使其不会被 reactive 包裹,也就不会成为 Vue3 中的响应式对象
import { reactive, markRaw } from 'vue'
const state = reactive({
count: 0,
obj: {
name: '张三'
}
})
markRaw(state.obj)
console.log(state.hasOwnProperty('__v_raw'))
state.obj.name = '李四'
console.log(state.obj.name)