主要是vue3以后,不能通过 params 传递参数,以前路由跳转的时候,通过 params 传递参数很好用,官方建议用pinia
import { defineStore } from 'pinia'
export const useCourseVideoStore = defineStore({
id: 'toCourseVideo',
state: () => {
return {
courseId:0,
}
},
actions: {
setCourseId(val){
this.courseId = val
}
},
getters: {
getCourseId(){
return this.courseId
}
},
})
//使用
import { useCourseVideoStore } from '~/store/course-video'
const courseVideoStore = useCourseVideoStore()
courseVideoStore.setCourseId(this.$route.params.id)
const courseVideoStore = useCourseVideoStore()
let courseId = courseVideoStore.getCourseId
