从零开始搭建博客网站-----构建项目

构建项目

视频参考链接

  1. 构建一个项目文件(node为17.16.0版本)
    构建的过程中可能会出现一个选项,选择vue+JavaScript
npm init vite@latest easyblog-front-admin

在这里插入图片描述

  1. 安装相关依赖
cd easyblog-front-admin
npm install

从零开始搭建博客网站-----构建项目_第1张图片
3. 运行

npm run dev

从零开始搭建博客网站-----构建项目_第2张图片
从零开始搭建博客网站-----构建项目_第3张图片
好了,一个vue项目就算新建完成了。

清理一下新建的项目的内容

  1. app.vue
    从零开始搭建博客网站-----构建项目_第4张图片
  2. 建立路由文件并安装路由
    从零开始搭建博客网站-----构建项目_第5张图片
  3. 在router下新建index.js文件,并写如下内容
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
    {}
];
//这里不是通过new来创建,通过createRouter 方法创建,使用的模式不是通过mode来定义
const router = createRouter({
    routes,
    history: createWebHistory(),
})

export default router
  1. 修改main.js文件,引用router
    从零开始搭建博客网站-----构建项目_第6张图片
  2. 配置代码片段补全
    参考链接
    从零开始搭建博客网站-----构建项目_第7张图片
    需要补全的文件有三个,文件内容如下:
    vue.json
{
		"Print to console": {
		  "prefix": "vue3",
		  "body": [
			"",
			"",
			"",
			"",
			"",
		],
		  "description": "Log output to console"
		}
	
}

vue-html.json

{
	"el-form模板": {
		"prefix": "el-form",
		"description": "创建el-form",
		"body": [
			",
			"  :model=\"formData\"",
			"  :rules=\"rules\"",
			"  ref=\"formDataRef\"",
			"  label-width=\"80px\"",
			">",
			"",
			"  ",
			"    ",
			"  ",
			"",
			"  ,
			"    label=\"\"",
			"    prop=\"\"",
			"    clearable",
			"    placeholder=\"提示信息\"",
			"    type=\"textarea\"",
			"    :rows=\"5\"",
			"    :maxlength=\"150\"",
			"    resize=\"none\"",
			"    show-word-limit",
			"    v-model=\"formData.\"",
			"  >",
			"  ",
			"",
			"  ",
			"    ",
			"      显示信息",
			"      显示信息",
			"    ",
			"  ",
			"",
			"  ",
			"    ",
			"      ",
			"      ",
			"    ",
			"  ",
			"",
		]
	},
	"el-input模板": {
		"prefix": "el-input",
		"description": "创建el-input",
		"body": [
			"",
			"  ",
			"    ",
			"  ",
		]
	},
	"el-textarea模板": {
		"prefix": "el-textarea",
		"description": "创建el-input",
		"body": [
			"",
			",
			"   label=\"\"",
			"   prop=\"\"",
			"   clearable",
			"   placeholder=\"提示信息\"",
			"   type=\"textarea\"",
			"   :rows=\"5\"",
			"   :maxlength=\"150\"",
			"   resize=\"none\"",
			"   show-word-limit",
			"   v-model=\"formData.\"",
			" >",
			"",
		]
	},
	"el-radio模板": {
		"prefix": "el-radio",
		"description": "创建el-radio",
		"body": [
			"",
			"  ",
			"    ",
			"      显示信息",
			"      显示信息",
			"    ",
			"  ",
		]
	},
	"el-select模板": {
		"prefix": "el-select",
		"description": "创建el-select模板",
		"body": [
			"",
			"  ",
			"    ",
			"      ",
			"      ",
			"    ",
			"  ",
		]
	},
}

javascript.lson

{
	"dialog弹窗配置": {
		"prefix": "dialogConfig",
		"description": "弹窗config配置",
		"body": [
			"const dialogConfig = reactive({",
			"  show: false,",
			"  title: \"标题\",",
			"  buttons: [",
			"   {",
			"    type: \"danger\",",
			"    text: \"确定\",",
			"    click: (e) => {",
			"      submitForm();",
			"    },",
			"  },",
			" ],",
			"});"
		]
	},
	"watch使用": {
		"prefix": "watch",
		"description": "快速实现watch",
		"body": [
			"watch(() => (newVal, oldVal) => {}, { immediate: true, deep: true });",
		]
	}
}
  1. 创建view文件夹,并且创建Index.js文件,Index文件内容如下
    从零开始搭建博客网站-----构建项目_第8张图片

完成了一个简单的路由映射

涉及的三个文件如图
从零开始搭建博客网站-----构建项目_第9张图片
从零开始搭建博客网站-----构建项目_第10张图片
从零开始搭建博客网站-----构建项目_第11张图片
从零开始搭建博客网站-----构建项目_第12张图片

修改一下配置文件,对路径进行索引配置

从零开始搭建博客网站-----构建项目_第13张图片
内容如下:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    hmr: true,
    port: 3001,
    proxy: {
      '/api': {
        target: "http://localhost:8081/", // 目标代理接口地址
        secure: false,
        changeOrigin: true, // 开启代理,在本地创建一个虚拟服务端
        pathRewrite: {
          '^/api': '/api',
        },
      },
    },
  },
  resolve: {
    // 配置路径别名
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
})

还需要安装path包

 npm install path --save

项目的初始搭建就完成啦!整个过程还算顺利!

你可能感兴趣的:(java)