博客说明: 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除;如有什么地方存在异议,请在评论区或私信指出,谢谢! Vuex 是一个状态管理工具 (store是唯一的;存数据;取数据;改数据) ① 安装 ② 导入 ③ 使用 ④ 实例化 例: ⑤ 在实例中注册 注: 注: ① 分模块 ② 分模块后的重名问题 如果getters 重名会报错; namespaced: true, 命名空间 启用命名空间后,mutations或actions 方法名 变为 模块名/方法名 前端路由:根据不同的url切换组件 ① 引入vuerouter ② 使用VueRouter ③ 实例化 ④ ⑤ App.vue中使用如下代码 router-link-exact-active router-link-active (子路由有样式,父路由也有) ①传递少量参数 ②监控参数变化 ③ 编程式导航(适合传多个参数) 在public/index.html 中使用从BootCDN引过来的 可以在入口文件 main.js使用命令 把请求的所有方法,都封装起来,需要请求时调用 1)后端:cors 2)前端:正向代理 创建vue.config.js文件 nextTick 延迟执行回调函数,直到dom就绪 【附】Vue中文教程
一、Vuex
npm i vuex --save
import Vuex from 'vuex'
Vue.use(Vuex)
var store = new Vuex.Store({ state:{ n:666 }, mutations:{ XXX(state,payload){ state.n+=payload } } })
new Vue({ ... store, ... })
mutaions:{ XXX(state,payload){ state.n+=payload } }
this.$store.commit("mutations里的方法名",参数)
getters:{ 属性(state){ return 计算属性的值 } }
异步方法(context,payload){ 异步成功的回调里 context.commit("mutaions里的同步方法",传参) }
this.$store.dispatch("actions里的异步方法","参数");
var 模块={ state:{},mutations:{},actions:{} } new Vuex.Store({ modules:{ 模块的名字:引入的模块,.... } }) // state 有区别 this.$store.state.模块名.变量 // 其他的mutations actions,getters里的方法调用和之前一样
mutaions方法重名,各个模块的里的这个方法都会调用;
actions方法重名,各个模块里的方法都会调用;
...mapState("模块名","变量"){{模块名.变量}} ...mapGetters({ 变量: 模块名/变量 }) ...mapMutations({ 方法名: 模块名/mutaions里的方法名 }) ...mapActions({ 方法名:模块名/actions里的方法名 })
二、Vue路由
后端路由:根据不同的请求返还不同的内容
npm i vue-router —save
import VueRouter from 'vue-router'
Vue.use(VueRouter)
var router = new VueRouter({ routes:[ { path:'xxx', component:Com }.... ] })
new Vue({ ... router ... })
<router-view /> <router-link to="/one">xxx</router-link>
history 模式
hash 模式<router-view name="xxx" /> { path:xxx, components:{ default:组件, router-view的名字:渲染组件; } }
{ path:"**", component:NotFound, }
{ path:'/xxx/:p', component:Xxx } this.$route.paramms.p(参数变量)
watch:{ $route:{ handler(n){ n 相当于this.$route n.meta.flag 可以拿到路由的元数据 }, immediate:true } }
this.$router.push({name:'xxx',params:{key:value....},query:{key:vaule...}}) // 跳转到名字叫 xxx路由对象,带过去params对象里的参数,并且把query里的健值对放到 ?后面 // 拿到query 传的值 this.$route.query.变量
v-enter v-enter-active v-enter-to v-leave v-leave-active v-leave-to <transtion mode="out-in"> out-in 是表示先退场再进场 <router-view /> </transtion>
animate.css即可<link href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.7.2/animate.css" rel="stylesheet"> <transition mode="out-in" enter-active-class="animated slideInLeft" leave-active-class="animated slideOutLeft">
// 全局守卫 beforeEach(to,from,next) // to:就是切换到路由的对象; from:当前路由的对象 ;next:跳转 afterEach(to,from) // 路由独享的守卫 beforeEnter // 组件内的守卫 // 路由进入之前 beforeRouteEnter( 比beforeCreate要早) next((vm)=>{ vm.组件里的数据 }) //路由更新之前 beforeRouteUpdate //路由离开之前 beforeRouteLeave
三、axios
npm i axios --save
axios.get('/user?ID=12345') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } }).then(function(res) { console.log(res) });
v-if 可以保证数据返回后再渲染组件
import axios from 'axios'; Vue.prototype.$axios=axios
res.setHeader("Access-Control-Allow-Origin","*");
module.exports ={ devServer:{ //开发服务器设置 proxy:{ //代理 "/hd":{ "target":"https://localhost:3000", "changeOrigin":true, "pathRewrite":{ "^/hd":"" } } } } }
this.$nextTick(callback);
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算