vue3注意事项

1、ref响应式数据的改动需要通过 .value赋值

reactive定义的数据 数组则只能通过使用数组的方法来更替。

2、vue3不再支持filter数据过滤,但更接近react,所以可以使用

复制代码
//c.count需要过滤的数据
<text class="trolley-count">{{trolleyCount(c.count)}}</text>

const trolleyCount = (_count:number) =>{
	if(_count === 0){
		return 0
	}else if(_count<100){
		return _count
	}else{
		return '99+'
	}
}

3、vue3不适合使用this,所以refs也没办法this.$refs,但是可以使用ref(vue3非vue2的)创建一个NULL的绑定数据

复制代码
<div ref="popup"></div>


const popup = ref(null);

4、props接收参数的方式也改为了defineProps

复制代码
import { defineProps} from 'vue'
	const props = defineProps({
		id:{
			type:String,
			default: '0'
		}
	})
相关推荐
threerocks1 小时前
什么?我连 A2A、MCP 都没学会,现在又来了 AG-UI、A2UI.
前端·aigc·ai编程
牛奶2 小时前
如何自己写一个浏览器插件?
前端·chrome·浏览器
亿元程序员3 小时前
为什么Cocos都4.0了还有人用2.x?
前端
MomentYY3 小时前
AI 到底是“懂”,还是在“猜”?
前端·人工智能·ai编程
鹏毓网络科技3 小时前
Cursor Rules 文件配置实战:3 个隐藏参数让我每月少写 40% 样板代码
前端·github
没烦恼3013 小时前
无痕模式下 HTTP\-First 拦截引发的“页面刷新”误判
前端
ZhengEnCi3 小时前
Q02-Vue-React-index.html完全指南
vue.js·react.js·html
文心快码BaiduComate3 小时前
从个人提效到组织提效:Comate辅助构建自我进化的AI研发系统
前端·程序员
hunterandroid3 小时前
Compose 状态管理:remember、rememberSaveable 与状态提升
前端
星栈4 小时前
Dioxus 接数据库最容易写歪的 3 个地方:sqlx + SQLite 怎么接才顺
前端·rust·前端框架