当前位置: 首页 > news >正文

教育网站 怎么做吸引人seo怎么判断网站的好坏

教育网站 怎么做吸引人,seo怎么判断网站的好坏,如何制作电脑公司网站,西安市住房和城乡建设局官网目录 引言1. Vuex的简介1.1 什么是Vuex#xff1f;1.2 Vuex的核心概念 2. Vuex的值获取与改变(综合案例)3. Vuex的异步请求总结 引言 在现代Web开发中#xff0c;前端应用变得越来越复杂。随着应用规模的扩大和数据流的复杂性增加#xff0c;有效地管理应用的状态成为了一项… 目录 引言1. Vuex的简介1.1 什么是Vuex1.2 Vuex的核心概念 2. Vuex的值获取与改变(综合案例)3. Vuex的异步请求总结 引言 在现代Web开发中前端应用变得越来越复杂。随着应用规模的扩大和数据流的复杂性增加有效地管理应用的状态成为了一项重要任务。Vue.js作为一种流行的JavaScript框架提供了Vuex这个强大的状态管理库旨在解决这个问题。本文将深入探讨Vuex的核心概念和特点并通过实际案例展示如何使用Vuex进行数据获取、值变更和异步请求。 1. Vuex的简介 1.1 什么是Vuex Vuex是一个专为Vue.js应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态并以相应的规则保证状态的一致性和可预测性。Vuex的设计灵感来自于Flux和Redux但针对Vue.js的特点进行了优化和扩展。 1.2 Vuex的核心概念 在使用Vuex之前我们需要了解其核心概念 State即应用的状态保存在一个单一的JavaScript对象中。通过this.$store.state可以访问状态。Mutation用于变更状态的方法每个mutation都有一个字符串的事件类型和一个回调函数。通过commit方法触发mutation。Getter类似于组件中的计算属性用于从state中派生出一些状态。通过this.$store.getters可以访问getter。Action用于处理异步操作或批量提交mutation的方法。通过dispatch方法触发action。 2. Vuex的值获取与改变(综合案例) 首先需要两个页面 page1 templatedivh1page1/h1p改变state的值/p请输入:input v-modelmsg/button clickfun1获取state/buttonbutton clickfun2改变state/button/div /templatescriptexport default{data(){return {msg:mrz}},methods:{fun1(){alert(this.$store.state.eduName)},fun2(){this.$store.commit(setEduName,{eduName:this.msg})}}} /scriptstyle /style page2 templatedivh1page2/h1{{eduName}}/div/templatescriptexport default{data(){return {msg:mrz}},computed:{eduName(){return this.$store.getters.getEduName;}}} /scriptstyle /style 配置路由 import Vue from vue import Router from vue-router import HelloWorld from /components/HelloWorld import Login from /views/Login import Register from /views/Register import AppMain from /components/AppMain import LeftNav from /components/LeftNav import TopNav from /components/TopNav import AddBook from /views/book/AddBook import BookList from /views/book/BookList import page1 from /views/vuex/page1 import page2 from /views/vuex/page2Vue.use(Router)export default new Router({routes: [{path: /,name: Login,component: Login},{path: /Register,component: Register},{path: /AppMain,name: AppMain,component: AppMain,children:[{path: LeftNav,name: LeftNav,component: LeftNav},{path: TopNav,name: TopNav,component: TopNav},{path: /book/AddBook,name: AddBook,component: AddBook},{path: /book/BookList,name: BookList,component: BookList},{path: /vuex/page1,name: page1,component: page1},{path: /vuex/page2,name: page2,component: page2}]}] }) 建包store以及五个js文件 state.js export default{eduName:唱歌会跑调Y } mutations.js export default{setEduName:(state,payload){state.eduName payload.eduName} } getters.js export default{getEduName:(state){return state.eduName;} } index.js import Vue from vue import Vuex from vuex import state from ./state import getters from ./getters import actions from ./actions import mutations from ./mutations Vue.use(Vuex) const store new Vuex.Store({state,getters,actions,mutations})export default store 配置main.js(import store from ‘./store’) // The Vue build version to load with the import command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from vue //开发环境下才会引入mockjs // process.env.MOCK require(/mock) // 新添加1 import ElementUI from element-ui // 新添加2避免后期打包样式不同要放在import App from ./App;之前 import element-ui/lib/theme-chalk/index.css import App from ./App import router from ./router import store from ./store // 新添加3 Vue.use(ElementUI) Vue.config.productionTip false/* eslint-disable no-new */ import axios from /api/http import VueAxios from vue-axiosVue.use(VueAxios,axios) new Vue({el: #app,router,store,data(){return{Bus:new Vue()}},components: { App },template: App/ }) 这样获取和改变就OK了看看效果 点击改变 page2的值发生改变 3. Vuex的异步请求 3.1 异步请求的必要性 在现代Web应用中我们经常需要进行异步操作如获取后端数据、发送网络请求等。Vuex提供了一种机制来处理这种场景并保证状态的一致性。 3.2 使用Actions进行异步操作 在Vuex中我们可以定义actions来进行异步操作。以下是一些使用actions的示例 page1 templatedivh1page1/h1p改变state的值/p请输入:input v-modelmsg /button clickfun1获取state/buttonbutton clickfun2改变state/buttonbutton clickfun3改变state/buttonbutton clickfun4请求后台/button/div /templatescriptexport default {data() {return {msg: mrz}},methods: {fun1() {alert(this.$store.state.eduName)},fun2() {this.$store.commit(setEduName, {eduName: this.msg})},fun3() {this.$store.dispatch(setEduNameAsync, {eduName: this.msg})},fun4() {this.$store.dispatch(setEduNameAjax, {eduName: this.msg,_this:this})}}} /scriptstyle /style actions.js export default{setEduNameAsync:(context,payload){setTimeout(function(){context.commit(setEduName,payload)},15000)},setEduNameAjax:(context,payload){let _this payload._thislet url _this.axios.urls.Vuex_Ajax;let params {resturantName: payload.eduName}_this.axios.post(url, params).then(r {console.log(r)}).catch(e {})} } 同步用commit异步用dispatch,期间主页this的局限,在actions.js调用不到全局this的实例需要用传参代替将参数带过去才能发送Ajax请求.另外注意http发送请求超时时间一般设置为10秒超过10秒及超时则不会相应数据在用deBug的情况下经常会出现数据相应不到的情况需注意 // axios默认配置 axios.defaults.timeout 10000; // 超时时间 总结 本文深入介绍了Vuex的核心概念和特点并通过三个大目录展示了在实际应用中如何使用Vuex进行状态管理。我们学习了如何获取和改变Vuex中的值以及如何处理异步请求。Vuex作为Vue.js生态系统中的重要组成部分在复杂应用开发中扮演着关键的角色。希望本文对于理解和应用Vuex有所帮助。
http://www.hkea.cn/news/14401536/

相关文章:

  • 定制建站 app建设网站建设价格比较
  • 禅城区网站建站网站dede网站移动端怎么做
  • 齐博网站模板网站二级目录 修改路径
  • 建设一个下载网站网络营销的特点主要有
  • 做网站看好金石网络岳阳关键词优化
  • 厦门市建设局官方网站成都网页设计培训哪家好
  • 做问卷赚钱最好似网站51个人网站怎么打开
  • 51网站空间还有吗什么网站发布建设标准
  • 网站SEM优化如何做奥德贵阳网络推广公司
  • 橙色网站模板网站建设公司图片
  • 备案需要写网站建设方案书wordpress文章推荐插件
  • 关于设计方面的网站论坛网站有哪些
  • 哪家手机网站建设国内建网站软件
  • 固安网站建设顺德龙江做网站
  • 做外贸有必要做个网站吗广告设计网站哪个好
  • 动漫设计与制作课程seo优化排名怎么做
  • 成都网站开发排名家庭网络组网方案
  • 网站被百度惩罚怎么办wordpress置顶
  • 上海网站建设乐云seowordpress 顺序
  • 专门更新最新设计的网站wordpress 链接提交表单
  • 网站页面模板 建设中西安发布信息的平台
  • 做网站的用户需求分析网络服务器设备
  • 深圳狮科网站建设沈阳高端网站定制
  • 公司起名字免费软件seo是什么东西
  • 网站百度地图wordpress博客无法评论
  • 网站手机版管理链接如何在百度做网站推广
  • 广州做网站信科网络长安网站建设价格
  • 网站功能模块设计怎么写项目外包网站
  • 职业医生继续做学分市哪个网站wordpress实战
  • 网站竞价推广怎么做邢台手机网站建设公司