1.路由

<script>
import { useRouter, useRoute } from 'vue-router'
export default {
  setup() {
    const router = useRouter() // 组件内路由
    const route = useRoute() // 组件内路由信息
  }
}
</script>

2.vuex

  • 创建store
import { createStore } from 'vuex'
import login from './login'

const store = createStore({
  state: {},
  mutations: {},
  actions: {},
  modules: {
    login
  }
})

export default store

  • 组件内使用store
<script>
import { useStore } from 'vuex'
export default {
  setup() {
    const store = useStore()
    const state = store.state
   	const methods = {
   	  // 处理commit
      handleMutation: () => {
        store.commit(...)
      },
      // 处理dispatch
      handleAction: () => {
        store.dispatch(...)
      }
   	}

    return {
      ...methods 
    }
  }
}
</script>
Logo

前往低代码交流专区

更多推荐