如何挂载全局?
// main.js
const app = createApp(App);
app.config.globalProperties.$request = request;
// index.vue
import { getCurrentInstance } from 'vue';
const globalProperties = getCurrentInstance().appContext.config.globalProperties;
globalProperties.$request()
ref和reactive的区别?
定义数据
ref通常用来定义基本类型数据
reactive用来定义:对象(或者数组)类型数据
ref也可以用来定义对象或者数组类型的数据,内部会通过reactive转为代理对象
原理
ref通过Object.defineProperty()的get和set实现数据代理。
reactive使用Proxy实现数据代理,并且通过Reflect操作源对象内部的数据。
使用
ref操作数据需要.value,template模板中不需要。
reactive都不需要.value