您现在的位置是:网站首页> 编程资料编程资料

关于VueRouter导入的全过程_vue.js_

2023-05-24 354人已围观

简介 关于VueRouter导入的全过程_vue.js_

router

nanoid的使用

​ --生成随机id

引入

yarn add nanoid

使用

import {nanoid} from 'nanoid' var id = nanoid()

路由

1-1 安装依赖

yarn add vue-router

1-2 引入

router/index.js 

import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) import Movie from '../pages/Movie/index.vue' import Music from '../pages/Music/index.vue' const routes = [ { path:"/music", component:Music }, { path:"/movie", component:Movie } ] const router = new VueRouter({ routes, mode:"history" }) export default router; 

1-3 在main.js中使用

import Vue from 'vue' import App from './App.vue' import router from './router' Vue.config.productionTip = false new Vue({   router,   render: h => h(App), }).$mount('#app')

1-4 App.vue

全局过滤器

在main.js中挂载在Vue原型上

Vue.filter("handleStr",function(val){   if(val.length > 3){     val = val.slice(0,3) + '...'   }   return val }) 

element-ui

安装依赖

yarn add element-ui

main.js

.... import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI); ...

全局组件

import Loading from '../components/Loading.vue' Vue.component("Loading",Loading)

Vuc-cli中的视配

只在手机端

lib-flexible 阿里

1-1 安装依赖

yarn add lib-flexible postcss-pxtorem@5.1.1

1-2 配置文件

新建postcss.config.js

module.exports = {   plugins: {     'postcss-pxtorem': {       rootValue: 75,       propList: ['*'],     },   }, };

1-3 main.js

导入lib-flexible

import 'lib-flexible/flexible.js'

1-4 public/index.html

将此行注释,关闭视口

1-5 在pc端视配

slot封装动画

// #1 定义一个组件 
// #2 使用 

项目初始化

1、rem 2、asssreset.css

1-1 .router-link-active

被选中的路由样式

.router-link-active{     color: #ff2d51;   }

1-2 动态显示tabbar

​ – 在路由配置中增加一条meta属性

const routes = [   {     path: '/films',     name: 'Films',     component:Films,     meta:{       isNav:true     }   },   {     path: '/article',     name: 'Article',     component:Article,     meta:{       isNav:true     }   },   {     path: '/center',     name: 'Center',     component:Center,     meta:{       isNav:true     }   },   {     path:"/movie/:id",     name:'MovieDetail',     component:MovieDetail   } ]

通过v-if动态显示

1-3 跳转回前一个页面

this.$router.back()

1-4轮播

yarn add vue-preview 
import VuePreview from 'vue-preview' Vue.use(VuePreview)

vant ui的按需导入

1-1 安装依赖

yarn add vant babel-plugin-import

1-2 配置babel.config.js

module.exports = {   presets: [     '@vue/cli-plugin-babel/preset'   ],   plugins: [     ["import", {       "libraryName": "vant",       "libraryDirectory": "es",       "style": true     }]   ] }

1-3 配置main.js

import {Button} from 'vant' Vue.use(Bu
                
                

-六神源码网