Mrcdh技术博客 Mrcdh技术博客
首页
  • Html5
  • Javascript
  • Nodejs
  • electron
  • Android
  • 微信公众号
  • 框架
  • 其他
  • Mysql
  • PHP
  • Python
  • java
  • Gulp
  • 其它
  • 网站
  • 资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Mrcdh

全栈开发小学生
首页
  • Html5
  • Javascript
  • Nodejs
  • electron
  • Android
  • 微信公众号
  • 框架
  • 其他
  • Mysql
  • PHP
  • Python
  • java
  • Gulp
  • 其它
  • 网站
  • 资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • element-ui

  • vue3

    • pinia持久化插件pinia-plugin-persist的使用
    • Vue3项目搭建
      • 安装 vue
      • 安装 vue-router
      • 安装 pinia
      • 安装 pinia-plugin-persistedstate
      • 安装 Element-Plus
      • 安装 tailwindcss
    • steup下调用子组件方法
    • Vue3使用Typescript常见问题
  • vue实现图片文件的显示和上传
  • composition-api
  • vue常用eslint配置模板
  • vue.config.js常用配置
  • vuepress-theme-vdoing本站使用主题
  • vue常见问题
  • 常用插件

  • 《Vuejs》
  • vue3
mrcdh
2024-12-25
目录

Vue3项目搭建

# 安装 vue

文档https://cn.vuejs.org/guide/introduction.html (opens new window)

npm i vue@latest
1
import { createApp } from "vue";
import App from "./App.vue";

const app = createApp(App);

app.mount("#app");
1
2
3
4
5
6

# 安装 vue-router

文档https://router.vuejs.org/zh/introduction.html (opens new window)

npm i vue-router@4
1
import { createMemoryHistory, createRouter } from "vue-router";

import HomeView from "./HomeView.vue";
import AboutView from "./AboutView.vue";

const routes = [
  { path: "/", component: HomeView },
  { path: "/about", component: AboutView },
];

const router = createRouter({
  history: createMemoryHistory(),
  routes,
});
app.use(router);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 安装 pinia

文档https://pinia.vuejs.org/zh/introduction.html (opens new window)

npm i pinia
1
import { createPinia } from "pinia";

const pinia = createPinia();

app.use(pinia);
1
2
3
4
5

# 安装 pinia-plugin-persistedstate

pinia 持久化文档https://prazdevs.github.io/pinia-plugin-persistedstate/zh/guide/ (opens new window)

npm i pinia-plugin-persistedstate
1
import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
app.use(pinia);
1
2
3
4
5
6
import { defineStore } from "pinia";
import { ref } from "vue";

export const useStore = defineStore(
  "main",
  () => {
    const someState = ref("hello pinia");
    return { someState };
  },
  {
    persist: true, // 声明为true为持久化存储
  }
);
export const useStore = defineStore("store", {
  state: () => ({
    someState: "hello pinia",
  }),
  persist: {
    key: "my-custom-key",
  },
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 安装 Element-Plus

文档https://cn.element-plus.org/zh-CN/ (opens new window)

npm i element-plus --save
1
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

app.use(ElementPlus);
1
2
3
4

# 安装 tailwindcss

文档https://tailwindcss.com/docs/installation (opens new window)

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
1
2
// tailwind.config.js
/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
1
2
3
4
5
6
7
8
9
10
11
12
@tailwind base;
@tailwind components;
@tailwind utilities;
1
2
3
#vue3
上次更新: 2024/12/25, 14:12:27
pinia持久化插件pinia-plugin-persist的使用
steup下调用子组件方法

← pinia持久化插件pinia-plugin-persist的使用 steup下调用子组件方法→

最近更新
01
uniapp常见问题
03-19
02
使用pnpm的monorepo组织项目
11-01
03
出海技术栈和工具
10-30
更多文章>
Theme by Vdoing | Copyright © 2020-2025 Mrcdh | 苏ICP备2020058908号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×