vue3 script setup 问题小记

1、在页面中this指向会取消
需要在当前操作页面引入vue的getCurrentInstance方法
import { getCurrentInstance } from ‘vue’;
然后
const { proxy } = getCurrentInstance()
用 proxy代替this

2、vue3 和 vue2的全局变量是不一样的
// Vue 2.x
import Vue from ‘vue’;
Vue.prototype.$http = () => {}
// Vue 3.x

import { createApp } from ‘vue’;
import App from ‘./App.vue’;
const app = Vue.createApp(App)
app.config.globalProperties.$http = () => {}

这是在main.js中生名全局变量
如在组建内生名vue2 没有变化vue3 则需要
import { getCurrentInstance } from ‘vue’;
const { appContext } = getCurrentInstance()
appContext.config.globalProperties.$http = () => {}

3.vue3数据监听watch
在对象数据变化的时候 正常的写法 vue3是监听到对象变化的
如: import { watch, defineProps } from ‘vue’;
const props = defineProps({
//子组件接收父组件传递过来的值
info: Objec

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值