diff --git "a/\350\265\265\346\254\243/0513.md" "b/\350\265\265\346\254\243/0513.md" new file mode 100644 index 0000000000000000000000000000000000000000..a02df60d28d909956034e26e28e30cd9c2db4123 --- /dev/null +++ "b/\350\265\265\346\254\243/0513.md" @@ -0,0 +1,108 @@ +Vue 3 + Pinia + 动态路由:集成与使用指南 +============================ + +1\. 安装依赖 +-------- + +首先确保已安装Vue 3、Vue Router和Pinia。在`package.json`中添加: + + "dependencies": { + "vue": "^3.2.0", + "vue-router": "^4.0.15", + "pinia": "^2.0.0" + } + + +2\. 设置Vue和Pinia +--------------- + +在`main.js`或`vite.config.js`(如果是Vite)中,配置Vue和Pinia: + + import { createApp } from 'vue'; + import { createPinia } from 'pinia'; + import App from './App.vue'; + + const app = createApp(App); + app.use(createPinia()); + + // 如果使用Vite,添加以下配置 + if (process.env.NODE_ENV === 'production') { + createApp(App).use(createPinia()); + } + + app.mount('#app'); + + +3\. 创建Pinia Store +----------------- + +创建一个名为`routerStore.js`的文件,用于存储动态路由相关数据: + + import { defineStore } from 'pinia'; + + export const useRouterStore = defineStore('routerStore', { + state: () => ({ + routes: [], // 存放动态路由配置 + }), + actions: { + addRoute(route) { + this.routes.push(route); + }, + removeRoute(routeKey) { + this.routes = this.routes.filter(r => r.key !== routeKey); + }, + }, + }); + + +4\. 动态路由配置 +---------- + +在Vue Router的配置文件(例如`router/index.js`)中,使用`createRoutes`动态生成路由: + + import { createRouter, createWebHistory } from 'vue-router'; + import { useRouterStore } from './routerStore'; + + const router = createRouter({ + history: createWebHistory(), + routes: routerStore.routes, // 从store中读取 + // 使用动态生成的路由 + dynamic: { + path: '/user/:userId', + component: (route) => import(/* webpackChunkName: "user" */ '@/views/User.vue'), + // 使用store中的数据 + props: (route) => ({ userId: route.params.userId }), + }, + }); + + router.beforeEach((to, from, next) => { + // 在每次路由变化前,更新store中的路由信息 + useRouterStore().addRoute(to); + }); + + export default router; + + +5\. 在组件中访问store +--------------- + +在需要使用动态路由数据的组件中,使用`useStore`方法: + + + + \ No newline at end of file diff --git "a/\350\265\265\346\254\243/0514.md" "b/\350\265\265\346\254\243/0514.md" new file mode 100644 index 0000000000000000000000000000000000000000..34940bbb288b973ae6812f46f71735ef9a690bf0 --- /dev/null +++ "b/\350\265\265\346\254\243/0514.md" @@ -0,0 +1,54 @@ +* * * + +Web API 概念笔记 +============ + +1\. 定义 +------ + +Web API(Web Application Programming Interface)是一组定义了如何在网络上进行数据交换的规范。它允许不同的软件系统相互通信,通常是通过HTTP协议。 + +2\. 类型 +------ + +* **浏览器API**:内置于浏览器中,如DOM API、Canvas API等,用于增强网页功能和交互性。 +* **服务器API**:部署在服务器上,如RESTful API、SOAP API等,用于提供数据和服务给客户端。 + +3\. 关键特性 +-------- + +* **无状态**:每个请求都是独立的,服务器不保存客户端状态。 +* **可缓存**:客户端可以缓存响应以提高性能。 +* **统一接口**:使用标准的HTTP方法(GET, POST, PUT, DELETE等)。 + +4\. 常见用途 +-------- + +* **数据交换**:允许应用程序之间共享数据。 +* **服务集成**:集成第三方服务,如支付、地图、社交网络等。 +* **应用扩展**:通过API扩展应用功能,如插件、扩展等。 + +5\. 开发注意事项 +---------- + +* **安全性**:确保API的安全性,如使用OAuth、API密钥等。 +* **文档**:提供详细的API文档,包括请求和响应的示例。 +* **版本控制**:管理API的版本,确保向后兼容性。 + +6\. 示例代码 +-------- + + // 使用Fetch API调用RESTful API + fetch('https://api.example.com/data', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer your_token' + } + }) + .then(response => response.json()) + .then(data => console.log(data)) + .catch(error => console.error('Error:', error)); + + +* * * \ No newline at end of file diff --git "a/\350\265\265\346\254\243/0516.md" "b/\350\265\265\346\254\243/0516.md" new file mode 100644 index 0000000000000000000000000000000000000000..95167f1b8354a5ed5f2e12b283574b95261c3bd2 --- /dev/null +++ "b/\350\265\265\346\254\243/0516.md" @@ -0,0 +1,177 @@ +## 路由增删改查 +1. main.js代码 +```js +import { createApp } from 'vue' +import './style.css' +import App from './App.vue' +import userList from './components/userList.vue' +import userEdit from './components/userEdit.vue' +let app = createApp(App); +import { createRouter, createWebHistory } from 'vue-router' +let router = createRouter({ + history: createWebHistory(), + routes: [ + { + path: '/', + component: userList + }, + { + path: '/edit', + component: userEdit + } + ] +}); +app.use(router); +app.mount('#app'); +``` +2. App.vue代码 +```html + + + +``` +2. UserList.vue代码 +```html + + + + +``` +3. UserEdit.vue代码 +```html + + +```