VueRoute(一)使用vueRoute+elementui搭建后台骨架

本篇文章基于vue2脚手架的基础上编写,如何搭建vue2脚手架请查看【搭建vue3脚手架,并且浅谈nodeJs和vue的关系】

一、Vue Router

Vue Router 是 Vue.js (opens new window)官方的路由管理器,主要用于页面的跳转,VueRouter官方文档传送门

下载

下载vue-router

npm install vue-router

将vueRoute整合到项目中

因为该项目是使用 Vue CLI 的项目,我们可以以项目插件的形式添加 Vue Router。CLI 可以生成路由相关的代码及两个示例路由。它也会覆盖我们的 App.vue,因此请确保在项目中运行以下命令之前备份这个文件:

# 在cmd终端执行
vue add router

# 会在main.js中生成以下代码
import VueRouter from 'vue-router'
import router from './router'
Vue.use(VueRouter)

# 并且会在项目根目录生成route文件夹以及route.js,route.js的内容如下
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

查看效果

然后就可以访问http://localhost:8080/about查看路由Demo
在这里插入图片描述

补充,在执行vue add router时,它会询问你是否用history模式的路由。路由有2种模式,hash模式和history模式,https://www.cnblogs.com/JRliu/p/9025290.html

二、Elementui

Elementui是饿了么团队基于vue打造的一套UI框架,Elementui官方文档传送门

下载

npm i element-ui -S

配置

修改main.js,加入如下所示内容

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

然后就可以使用啦

三、Less

vue使用<style lang="less" scoped></style>之后报错,如下图所示
在这里插入图片描述

然后npm i less less-loader -D后继续报错,如下所示

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.0.0" from @intervolga/optimize-cssnano-plugin@1.0.6
npm ERR!   node_modules/@intervolga/optimize-cssnano-plugin
npm ERR!     @intervolga/optimize-cssnano-plugin@"^1.0.5" from @vue/cli-service@4.5.13
npm ERR!     node_modules/@vue/cli-service
npm ERR!       peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.13
npm ERR!       node_modules/@vue/cli-plugin-babel
npm ERR!         dev @vue/cli-plugin-babel@"~4.5.0" from the root project
npm ERR!       3 more (@vue/cli-plugin-router, @vue/cli-plugin-vuex, the root project)
npm ERR!   peer webpack@"^4.0.0 || ^5.0.0" from @soda/friendly-errors-webpack-plugin@1.8.0
npm ERR!   node_modules/@soda/friendly-errors-webpack-plugin
npm ERR!     @soda/friendly-errors-webpack-plugin@"^1.7.1" from @vue/cli-service@4.5.13
npm ERR!     node_modules/@vue/cli-service
npm ERR!       peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.13
npm ERR!       node_modules/@vue/cli-plugin-babel
npm ERR!         dev @vue/cli-plugin-babel@"~4.5.0" from the root project
npm ERR!       3 more (@vue/cli-plugin-router, @vue/cli-plugin-vuex, the root project)
npm ERR!   16 more (@vue/cli-plugin-babel, @vue/cli-service, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev less-loader@"*" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: webpack@5.42.1
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^5.0.0" from less-loader@10.0.1
npm ERR!   node_modules/less-loader
npm ERR!     dev less-loader@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/dengzemiao/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/dengzemiao/.npm/_logs/2021-07-06T01_37_12_820Z-debug.log

问题原因:https://blog.csdn.net/weixin_45821811/article/details/121394553
解决办法:npm install less@3.9.0 less-loader@4.1.0 --save-dev
参考博客:https://blog.csdn.net/zz00008888/article/details/118515085

最终效果

在这里插入图片描述
该篇博客的代码可以到此处进行下载

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用 Maven 搭建 Spring Boot + Vue3 项目的步骤: 1. 创建一个 Maven 项目 在你的 IDE 中创建一个 Maven 项目,可以选择使用 Spring Initializr 快速生成一个 Spring Boot 项目骨架。 2. 添加 Spring Boot 依赖 在 pom.xml 文件中添加 Spring Boot 的依赖,例如: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 3. 添加 Vue3 依赖 在 pom.xml 中添加 Vue3 的依赖,例如: ``` <dependency> <groupId>org.webjars.npm</groupId> <artifactId>vue@3.0.0</artifactId> <version>3.0.0</version> </dependency> ``` 注意:这里使用了 WebJars,需要在项目中添加 WebJars 的依赖。 4. 配置 Maven 插件 在 pom.xml 文件中配置 Maven 插件,用于编译 Vue3 代码。例如: ``` <build> <plugins> <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.10.0</version> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <configuration> <nodeVersion>v12.16.2</nodeVersion> <npmVersion>6.14.4</npmVersion> </configuration> </execution> <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>install</arguments> </configuration> </execution> <execution> <id>npm build</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>run build</arguments> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 这里使用了 frontend-maven-plugin 插件来编译 Vue3 代码。 5. 创建 Vue3 项目项目根目录下创建一个名为 vue 的文件夹,用于存放 Vue3 项目代码。 在 vue 文件夹下执行以下命令,创建一个 Vue3 项目: ``` vue create . ``` 这里使用了点号(.)表示当前目录。 6. 配置 Vue3 项目vue 文件夹下创建一个 vue.config.js 文件,用于配置 Vue3 项目。例如: ``` module.exports = { outputDir: "../src/main/resources/static", indexPath: "../static/index.html", devServer: { proxy: { "/api": { target: "http://localhost:8080" } } } } ``` 这里将 Vue3 项目的输出目录设置为 src/main/resources/static,将 Vue3 项目的入口文件设置为 static/index.html,并配置了代理,将所有以 /api 开头的请求转发到 http://localhost:8080。 7. 编译项目项目根目录下执行以下命令,编译项目: ``` mvn clean install ``` 这里会自动编译 Vue3 项目,并将编译后的代码打包到 jar 包中。 8. 运行项目 在 target 目录下找到生成的 jar 包,执行以下命令,运行项目: ``` java -jar your-project.jar ``` 这里需要将 your-project.jar 替换为实际的 jar 包名称。 9. 访问应用 在浏览器中访问 http://localhost:8080,即可看到运行的应用。 以上就是使用 Maven 搭建 Spring Boot + Vue3 项目的步骤,希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我叫985

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值