摆烂人被迫学习
1、声明变量
首先引入ref 再const声明 使用的时候用 变量.value 取值
import {ref} from "vue"
const arr = ref([])
arr.value
2、声明函数
直接const 一个函数就好
const startInterval = () => {}
3、props的使用
声明props 需要用defineProps 使用的时候用 props.变量
const props = defineProps({
layout:{type:String, default:"1"}
})
props.layout
// 在template里面可以直接使用参数名(layout),但如果参数名为props,那就需要props.props
4、emits的使用
抛出click事件 activeId为参数 可传可不传
const emits = defineEmits(['click'])
const handleClick = () => emits('click',activeId)
5、ref的使用
//在父组件声明变量
const toRef = ref(null) <Dialog ref="toRef"></Dialog>
//显示子组件
const show = () => {
//调用dialog组件里面的showDialog方法
toRef.value.showDialog();
//toRef.value.show=true;不能自己修改组件里面的值
};
//在子组件里声明方法并且抛出去
const showDialog = () =>{}
defineExpose({showDialog})
6、router的使用
需要在页面先引入vue-router
import {useRouter} from "vue-router";
const router = useRouter()
const goZhfx = () => {
router.push({path:'/zhfx',query:{curDim:'yhfx'}})
};