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

thinkphp 网站开发抖音代运营业务介绍

thinkphp 网站开发,抖音代运营业务介绍,网站建设使用的基本技术,请教 网站建设价格一般多少钱一、简介 1.1Vuex 是什么 Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态#xff0c;并以相应的规则保证状态以一种可预测的方式发生变化。Vuex 也集成到 Vue 的官方调试工具 devtools extension (opens new window)#xf…一、简介 1.1Vuex 是什么 Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态并以相应的规则保证状态以一种可预测的方式发生变化。Vuex 也集成到 Vue 的官方调试工具 devtools extension (opens new window)提供了诸如零配置的 time-travel 调试、状态快照导入导出等高级调试功能。 1.2 什么是“状态管理模式” 一个简单的 Vue 计数应用开始 new Vue({// statedata () {return {count: 0}},// viewtemplate: div{{ count }}/div,// actionsmethods: {increment () {this.count}} })这个状态自管理应用包含以下几个部分 state驱动应用的数据源view以声明方式将 state 映射到视图actions响应在 view 上的用户输入导致的状态变化。 以下是一个表示“单向数据流”理念的简单示意 但是当我们的应用遇到多个组件共享状态时单向数据流的简洁性很容易被破坏 多个视图依赖于同一状态。来自不同视图的行为需要变更同一状态。 对于问题一传参的方法对于多层嵌套的组件将会非常繁琐并且对于兄弟组件间的状态传递无能为力。 对于问题二我们经常会采用父子组件直接引用或者通过事件来变更和同步状态的多份拷贝。以上的这些模式非常脆弱通常会导致无法维护的代码。 因此我们为什么不把组件的共享状态抽取出来以一个全局单例模式管理呢在这种模式下我们的组件树构成了一个巨大的“视图”不管在树的哪个位置任何组件都能获取状态或者触发行为 通过定义和隔离状态管理中的各种概念并通过强制规则维持视图和状态间的独立性我们的代码将会变得更结构化且易维护。 这就是 Vuex 背后的基本思想借鉴了 Flux (opens new window)、Redux (opens new window)和 The Elm Architecture (opens new window)。与其他模式不同的是Vuex 是专门为 Vue.js 设计的状态管理库以利用 Vue.js 的细粒度数据响应机制来进行高效的状态更新。 二、什么情况下我应该使用 Vuex Vuex 可以帮助我们管理共享状态并附带了更多的概念和框架。这需要对短期和长期效益进行权衡。 如果您不打算开发大型单页应用使用 Vuex 可能是繁琐冗余的。确实是如此——如果您的应用够简单您最好不要使用 Vuex。一个简单的 store 模式 就足够您所需了。但是如果您需要构建一个中大型单页应用您很可能会考虑如何更好地在组件外部管理状态Vuex 将会成为自然而然的选择。 三、安装 3.1 直接下载 / CDN 引用 https://unpkg.com/vuex https://unpkg.com/ , 提供了基于 NPM 的 CDN 链接。以上的链接会一直指向 NPM 上发布的最新版本。您也可以通过 https://unpkg.com/vuex2.0.0 这样的方式指定特定的版本。 在 Vue 之后引入 vuex 会进行自动安装 script src/path/to/vue.js/script script src/path/to/vuex.js/script3.2 NPM npm install vuex --save 3.3 Yarn yarn add vuex在一个模块化的打包系统中您必须显式地通过 Vue.use() 来安装 Vuex import Vue from vue import Vuex from vuexVue.use(Vuex)四、最简单的 StoreVuex 记数应用实例 提醒下面实例是在TestVue2的项目里运行的 4.1 TestVue2项目结构图 4.2 安装 vuex 3.1.0 npm install vuex3.1.0安装成功后查看package.json文件 4.3 创建一个 store 安装 Vuex 之后让我们来创建一个 store。创建过程直截了当——仅需要提供一个初始 state 对象和一些 mutation store文件夹里index.js文件代码 import Vue from vue import Vuex from vuex // 全局 Vue.use(Vuex) // https://www.jb51.net/javascript/297247rzd.htm // https://blog.csdn.net/weixin_44904953/article/details/129159961// export default new Vuex.Store({ const store new Vuex.Store({namespaced: true,state: {count: 0,},mutations: {increment(state) {state.count},decrement: state state.count--,getCount(state){return state.count},},actions: {// 异步任务 store.dispatchtryactions(context, val) { //第一个参数是context固定不变第二个是自定义参数setTimeout(() {context.commit(increment) //调用mutations中的方法修改state中的数据}, val);},},getters: {},})export default store;现在你可以通过 store.state 来获取状态对象以及通过 store.commit 方法触发状态变更 store.commit(increment)console.log(store.state.count) // - 14.4 注入store 为了在 Vue 组件中访问 this.$store property你需要为 Vue 实例提供创建好的 store。Vuex 提供了一个从根组件向所有子组件以 store 选项的方式“注入”该 store 的机制 在store文件里index.js里使用了Vue.use(Vuex)接下来在main.js将index.js导入 main.js文件代码 import Vue from vue import App from ./App.vue // 将 Vuex Store 注入到应用中 import store from ./store import router from ./router Vue.config.productionTip false // Vue.prototype.$store store// https://www.jb51.net/javascript/297247rzd.htm // 如果使用 ES6你也可以以 ES6 对象的 property 简写 (用在对象某个 property 的 key 和被传入的变量同名时) new Vue({router,store,render: h h(App), }).$mount(#app)// 使用 ES2015 语法 // new Vue({ // router: router, // store: store, // render: h h(App), // }).$mount(#app)再次强调我们通过提交 mutation 的方式而非直接改变 store.state.count是因为我们想要更明确地追踪到状态的变化。这个简单的约定能够让你的意图更加明显这样你在阅读代码的时候能更容易地解读应用内部的状态改变。此外这样也让我们有机会去实现一些能记录每次状态改变保存状态快照的调试工具。有了它我们甚至可以实现如时间穿梭般的调试体验。 由于 store 中的状态是响应式的在组件中调用 store 中的状态简单到仅需要在计算属性中返回即可。触发变化也仅仅是在组件的 methods 中提交 mutation。 4.4 创建两个vue文件 teststore1.vue代码 templatedivh1store 1 数量{{this.$store.state.count}}/h1!-- h1getComputedCount 数量{{getComputedCount}}/h1 --h1mapState 数量{{count}}/h1button clickincrement/buttonbutton clickdecrement-/button/brbutton clickdoactions点击两秒后数量自动加1/buttonbr /br /pbutton v-on:clickgetCount获取localCount最新值/button获取到的数量{{localCount}}/pbr /br /button clickopenTest2Page打开test2页面/button/div /templatescriptimport {mapState} from vuexexport default {name: teststore1,data() {return {localCount: 0,}},computed: {...mapState([count,]), //推荐这种方式},// watch: {// count: {// handler(newVal, oldVal) {// console.log(teststore1 watch 新的值: ${newVal} , 旧的值: ${oldVal})// },// }// },created() {console.log(teststore1 执行了 created )},activated() {console.log(teststore1 执行了 activated )},mounted() {console.log(teststore1 执行了 mounted , this.$store)},beforeUpdate() {console.log(teststore1 执行了 beforeUpdate )},updated() {console.log(teststore1 执行了 updated )},beforeDestroy() {console.log(teststore1 执行了 beforeDestroy )},destroyed() {console.log(teststore1 执行了 beforeDestroy )},methods: {increment() {this.$store.commit(increment)},decrement() {this.$store.commit(decrement)},// // 异步任务 store.dispatch doactions() {this.$store.dispatch(tryactions, 2000)},getCount() {this.localCount this.$store.state.countconsole.log(执行了 getCount this.localCount , this.localCount)},openTest2Page(){this.$router.push(/teststore2)},}} /scriptstylebutton {margin-left: 1.25rem;margin-top: 1.0rem;} /styleteststore2.vue代码 templatediv!-- h1store 2 数量{{this.$store.state.count}}/h1 --h1store 2 数量{{count}}/h1button clickincrement/buttonbutton clickdecrement-/buttonbutton clickgoBack返回到上个页面/button/div /templatescriptimport {mapState} from vuexexport default {name: teststore2,data() {return {mCount: 0,}},created() {console.log(teststore2 执行了 created )},activated() {console.log(teststore2 执行了 activated )},mounted() {console.log(teststore2 执行了 mounted , this.$store)},beforeUpdate() {console.log(teststore2 执行了 beforeUpdate )},updated() {console.log(teststore2 执行了 updated )},beforeDestroy() {console.log(teststore2 执行了 beforeDestroy )},destroyed() {console.log(teststore2 执行了 beforeDestroy )},computed: {...mapState([count,]),},mounted() {console.log(teststore2 执行了 mounted ,this.$store)},methods: {increment() {this.$store.commit(increment)},decrement() {this.$store.commit(decrement)},goBack(){this.$router.replace(/teststore1)}}} /scriptstylebutton {margin-left: 1.25rem;} /style五、启动TestVue2项目 TestVue2使用了vue-router可参考vue-router使用指南 在终端里输入下面命令 提醒因为电脑里node版本问题前面加了NODE_OPTIONS–openssl-legacy-provider NODE_OPTIONS--openssl-legacy-provider npm run serve六、效果图 home.vue页面 teststore1.vue页面 teststore2.vue页面 点击返回到上个页面teststore2.vue 七、TestVue2项目源码 点击查看TestVue2源码
http://www.w-s-a.com/news/54923/

相关文章:

  • 阿里巴巴网站开发是谁长沙自助模板建站
  • 阿里云网站方案建设书网络公司运营是干啥的
  • 南通seo网站排名优化nginx wordpress rewrite
  • 网站做成软件做内部网站费用
  • 浙江企业网站建设网站域名有了 网站如何建设
  • 学编程哪个机构有权威德州做网站优化
  • 最火的网站开发语言福州网站建设服务商
  • 嘉兴网站制作哪里好asp网站源码免费版
  • 如何给网站配置域名百度网站统计添加网址
  • 搭建wap网站磁力引擎
  • 如何给公司网站做推广个人网站可以做社区吗
  • 网站建设为什么不给源代码大理如何做百度的网站
  • 网站代理违法吗网站备份流程
  • 免费域名查询网站wordpress wordfence
  • h5响应式网站模板制作巴南网站制作
  • 网站方案报价软文什么意思
  • 电子商城网站如何建设上海公司车牌价格
  • 丽江网站设计公司专业公司网站设计企业
  • iis怎么建设网站特色产品推广方案
  • 道路建设网站专题品牌网站建设特色大蝌蚪
  • 网站开发组合 所有组合如何做com的网站
  • 电商网站怎么做的Wordpress 报表的插件
  • 纹理网站推荐买了两台服务器可以做网站吗
  • 机关公文写作网站南宁互联网推广
  • 五指山网站开发价格免费申请网站域名
  • 帝国音乐网站怎么做数据表电脑优化软件
  • 做国外网站收款怎么收建筑人才招聘网站
  • 毕设做桌面端还是网站sns社交网站 建设
  • 建设一个网站需要注意哪些内容wordpress 进销存
  • 沈阳市建设局网站sem优化师是什么意思