feat: 新增路由|状态管理依赖
This commit is contained in:
8
.yarnrc
Normal file
8
.yarnrc
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
registry "https://registry.npmmirror.com"
|
||||||
|
electron_mirror "https://npmmirror.com/mirrors/electron/"
|
||||||
|
node_gyp_mirror "https://npmmirror.com/mirrors/node-gyp/"
|
||||||
|
sass_binary_site "https://npmmirror.com/mirrors/node-sass/"
|
||||||
|
phantomjs_cdnurl "https://npmmirror.com/mirrors/phantomjs/"
|
||||||
|
electron_builder_binaries_mirror "https://npmmirror.com/mirrors/electron-builder-binaries/"
|
||||||
|
sqlite3_binary_host_mirror "https://npmmirror.com/mirrors/"
|
||||||
|
python_mirror "https://npmmirror.com/mirrors/python/"
|
||||||
8939
package-lock.json
generated
8939
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
src/App.vue
18
src/App.vue
@@ -1,10 +1,12 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
import HelloWorld from './components/HelloWorld.vue'
|
import HelloWorld from './components/HelloWorld.vue'
|
||||||
|
import { useMainStore } from './store'
|
||||||
|
|
||||||
onMounted(async () => {
|
const store = useMainStore()
|
||||||
let res = await window.myApi.handleSend('liaoruiruirurirui')
|
|
||||||
console.log(res)
|
onMounted(() => {
|
||||||
|
console.log('Vue应用已挂载,路由和Pinia已集成')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -18,6 +20,16 @@ onMounted(async () => {
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<HelloWorld msg="Vite + Vue" />
|
<HelloWorld msg="Vite + Vue" />
|
||||||
|
|
||||||
|
<!-- Pinia 状态管理示例 -->
|
||||||
|
<div style="margin: 20px; padding: 20px; border: 1px solid #ccc;">
|
||||||
|
<h3>计数器: {{ store.count }}</h3>
|
||||||
|
<button @click="store.increment()">+1</button>
|
||||||
|
<button @click="store.decrement()">-1</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 路由视图 -->
|
||||||
|
<router-view />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
13
src/main.js
13
src/main.js
@@ -1,5 +1,10 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from "vue";
|
||||||
import './style.css'
|
import "./style.css";
|
||||||
import App from './App.vue'
|
import App from "./App.vue";
|
||||||
|
import router from "./router";
|
||||||
|
import pinia from "./store";
|
||||||
|
|
||||||
createApp(App).mount('#app')
|
const app = createApp(App);
|
||||||
|
app.use(router);
|
||||||
|
app.use(pinia);
|
||||||
|
app.mount("#app");
|
||||||
|
|||||||
16
src/router/index.js
Normal file
16
src/router/index.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'Home',
|
||||||
|
component: () => import('../App.vue')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(),
|
||||||
|
routes
|
||||||
|
})
|
||||||
|
|
||||||
|
export default router
|
||||||
23
src/store/index.js
Normal file
23
src/store/index.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { createPinia } from 'pinia'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
// 创建pinia实例
|
||||||
|
const pinia = createPinia()
|
||||||
|
|
||||||
|
// 定义一个基本的store
|
||||||
|
export const useMainStore = defineStore('main', {
|
||||||
|
state: () => ({
|
||||||
|
count: 0
|
||||||
|
}),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
increment() {
|
||||||
|
this.count++
|
||||||
|
},
|
||||||
|
decrement() {
|
||||||
|
this.count--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default pinia
|
||||||
Reference in New Issue
Block a user