首页前端开发VUEvue3+ts项目安装路由

vue3+ts项目安装路由

时间2023-07-05 13:48:02发布访客分类VUE浏览1688
导读:安装路由npm install vue-router@4声明路由文件src/router/index.tsimport { createRouter, createWebHashHistory, RouteRecordRaw } from...

安装路由

npm install vue-router@4

声明路由文件src/router/index.ts

import {
 createRouter, createWebHashHistory, RouteRecordRaw }
     from "vue-router";
    
const routes:ArrayRouteRecordRaw>
=[
  {
    
    path:'/',
    name:'Home',
    component:()=>
import('../components/HelloWorld.vue') 
  }
,
  {
    
    path:'/a1',
    name:'a1',
    component:()=>
import('../components/a1.vue') 
  }
,
]
const router=createRouter({

  history:createWebHashHistory(),
  routes
}
)

export default router

修改main.ts

import {
 createApp }
     from "vue";
    
import App from "./App.vue";
    
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'


createApp(App).use(router).use(ElementPlus).mount("#app");
    

修改App.vue

template>
    
  router-link class="a_link" to="/">
    home/router-link>
    
  router-link to="/trans">
    transValue/router-link>
    
  router-view>
    /router-view>
    
/template>
    

效果:

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

vue.jsvue3

若转载请注明出处: vue3+ts项目安装路由
本文地址: https://pptw.com/jishu/290329.html
如何避免美国ASP主机服务器崩溃和故障? [oeasy]python0140_导入_import_from_as_namespace_

游客 回复需填写必要信息