Vue3学习入门

Vue

npm init vite@latest --template vue
cd
npm install
npm run dev

使用
main.js中引入

import { createApp } from "vue";
import App from "./App.vue";

const app = createApp(App)
app.mount("#app")

Vuex

npm install vuex --save-dev

使用

src目录下新建文件夹store/index.js

import { createStore } from "vuex";

export default createStore({
  state: { },
  mutations: { },
});

main.js中引入

import store from "./store/index";
app.use(store)

home.vue使用时

import { useStore } from "vuex";

export default {
  setup() {
    const store = useStore();
    const increment = () => {
      store.commit("increment");
    };
    .....
  },
};

Vue-Router

安装
npm install vue-router@4

使用
src下新建router/index.js

import { createRouter, createWebHashHistory } from "vue-router";

export default createRouter({
  history: createWebHashHistory(),
  routes: [
  ],
});

main.js引入

import router from "./router";

app.use(router);

Vite项目给路径别名

import  {join} from 'path';
export default defineConfig({
    resolve: {
        alias: {
            '@': join(__dirname, 'src')
        }
    }
})

你可能感兴趣的:(Vue3学习入门)