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

和淘宝同时做电商的网站织梦门户网站源码下载

和淘宝同时做电商的网站,织梦门户网站源码下载,wordpress 添加文章属性,智能产品创新设计目录 1. store/index.ts 2. main.ts 3. App.vue调用 4. 如果删除moduleA的namespaced属性, 保留moduleB的namespaced:true 5. 则App.vue修改为: 1. store/index.ts 注意: 需要使用时带上模块名称的namespaced必须为true, 不写或者为false时调用时不需要写模块名称(获取st…

目录

1. store/index.ts

2. main.ts

3. App.vue调用

4. 如果删除moduleA的namespaced属性, 保留moduleB的namespaced:true

5. 则App.vue修改为:


1. store/index.ts

注意: 需要使用时带上模块名称的namespaced必须为true, 不写或者为false时调用时不需要写模块名称(获取state的值必须加模块名)

import { createStore } from "vuex";
// A模块
const moduleA = {namespaced: true,state: {name: "moduleA",},getters: {newName(state) {return state.name;},},mutations: {changeName(state, payload) {state.name = payload;},updateAge(state, playLoad) {state.age = playLoad;},},actions: {changeAge({ commit }, age) {setTimeout(() => {commit("updateAge", age);}, 0);},},
};
// B模块
const moduleB = {namespaced: true,state: {name: "moduleB",age: 33,},getters: {newName(state) {return state.name;},},mutations: {changeName(state, payload) {state.name = payload;},updateAge(state, playLoad) {console.log("playLoad", playLoad);state.age = playLoad;},},actions: {changeAge(ctx, count) {console.log("触发了-模块B的action");setTimeout(() => {ctx.commit("updateAge", count);}, 1000);},},
};
export default createStore({// 分模块modules: {moduleA,moduleB,},
});

2. main.ts

import { createApp } from "vue";
import App from "./App.vue";
import * as Vue from "vue";
import store from './store';const app = createApp(App);
app.use(store);
app.mount("#app");

3. App.vue调用

<template><div id="container"><!-- 1、使用A模块的state数据 --><div>姓名: <input type="text" @change="changeAName($event)"></div><div>年龄: <input type="number" @change="changeAAge($event)"></div><h1>模块a:</h1><p>姓名(state): {{ store.state.moduleA.name }}</p><!-- 2、使用A模块的getters数据 --><p>姓名(getters): {{ store.getters["moduleA/newName"] }}</p><p>年龄: {{ store.state.moduleA.age }}</p><!-- 1、使用B模块的state数据 --><h1>模块b:</h1><div>姓名: <input type="text" @change="changeBName($event)"></div><div>年龄: <input type="number" @change="changeBAge($event)"></div><p>姓名(state): {{ store.state.moduleB.name }}</p><!-- 2、使用B模块的getters数据 $store.getters['模块名/计算属性']--><p>姓名(getters): {{ store.getters["moduleB/newName"] }}</p><p>年龄: {{ store.state.moduleB.age }}</p></div>
</template>
<script setup lang="ts">
import { useStore } from "vuex";// userStore可以拿到vuex仓库实例
const store = useStore();const changeAName = (e) => {store.commit('moduleA/changeName', e.target.value)
};
const changeAAge = (e) => {store.dispatch("moduleA/changeAge", e.target.value)
};const changeBName = (e) => {// 提交B模块的更改store.commit('moduleB/changeName', e.target.value)
};
const changeBAge = (e) => {// 传参用法store.dispatch("moduleB/changeAge", e.target.value)
};
</script>
<style lang='scss' scoped></style>

4. 如果删除moduleA的namespaced属性, 保留moduleB的namespaced:true

import { createStore } from "vuex";
// A模块
const moduleA = {state: {name: "moduleA",},getters: {newName(state) {return state.name;},},mutations: {changeName(state, payload) {state.name = payload;},updateAge(state, playLoad) {state.age = playLoad;},},actions: {changeAge({ commit }, age) {setTimeout(() => {commit("updateAge", age);}, 0);},},
};
// B模块
const moduleB = {namespaced: true,state: {name: "moduleB",age: 33,},getters: {newName(state) {return state.name;},},mutations: {// 更改数据函数changeName(state, payload) {state.name = payload;},updateAge(state, playLoad) {console.log("playLoad", playLoad);state.age = playLoad;},},actions: {changeAge(ctx, count) {setTimeout(() => {ctx.commit("updateAge", count);}, 1000);},},
};
export default createStore({// 分模块modules: {moduleA,moduleB,},
});

5. 则App.vue修改为:

<template><div id="container"><!-- 1、使用A模块的state数据 --><div>姓名: <input type="text" @change="changeAName($event)"></div><div>年龄: <input type="number" @change="changeAAge($event)"></div><h1>模块a:</h1><p>姓名(state): {{ store.state.moduleA.name }}</p><p>姓名(getters): {{ store.getters["newName"] }}</p><p>年龄: {{ store.state.moduleA.age }}</p><!-- 1、使用B模块的state数据 --><h1>模块b:</h1><div>姓名: <input type="text" @change="changeBName($event)"></div><div>年龄: <input type="number" @change="changeBAge($event)"></div><p>姓名(state): {{ store.state.moduleB.name }}</p><!-- 2、使用B模块的getters数据 $store.getters['模块名/计算属性']--><p>姓名(getters): {{ store.getters["moduleB/newName"] }}</p><p>年龄: {{ store.state.moduleB.age }}</p></div>
</template>
<script setup lang="ts">
import { useStore } from "vuex";// userStore可以拿到vuex仓库实例
const store = useStore();const changeAName = (e) => {store.commit('changeName', e.target.value)
};
const changeAAge = (e) => {store.dispatch("changeAge", e.target.value)
};const changeBName = (e) => {store.commit('moduleB/changeName', e.target.value)
};
const changeBAge = (e) => {store.dispatch("moduleB/changeAge", e.target.value)
};
</script>
<style lang='scss' scoped></style>

http://www.yayakq.cn/news/936077/

相关文章:

  • 黄埔建网站公司深圳营销策划公司哪家好
  • 网站建设公司专业网站开发制作网站建设与管理需要哪些证书
  • 织梦网站需要付费吗网站开发文案
  • 哈尔滨做网站网站建设和网站维护
  • 交流做病理切片的网站郑州美容网站建设
  • 上海做网站的公微信小程序官网网址
  • 滨海做网站的wordpress上传图片自动压缩
  • 泉州网站建设的步骤越秀电子商务网站建设
  • 百度收录哪个网站多智慧工厂管理系统
  • 网站建设的解决方案建筑案例分析网站
  • 网站怎么上传模板电子商务网站建设的书
  • 网站建设如何实现检索功能上海公共服务平台官网
  • 杭州网站制作培训WordPress手机插件耗费CPU
  • 做一网站多少钱学历提升的正规机构
  • 写作网站起点更合高明网站建设
  • 如何自己做搜索网站贵阳网站建设方案策划
  • 建设维护网站 未签订合同seo优化专员工作内容
  • 杭州微网站开发公司网站设计概念
  • 宝安第一网站国外做做网站
  • 南宁网站建设公司怎么接单开发技术网站开发技术路线
  • 湖州外贸网站建设北京规划建设 杂志 官方网站
  • 官方网站焊工证查询wordpress免费主题
  • 相城专业的网站建设赛车pk10计划网站建设
  • php综合网站源码网站功能介绍
  • 做网站需要什么证件吗济南360做网站电话
  • 注册网站需要多少钱开发一个app的注意事项
  • 网站建设架构图品牌高端网站制作官网
  • 公司网站建设南宁西安网页设计公司推荐
  • 网站建设好的公司专业服务营销型网站建设合同模板
  • 做网站后的总结口碑好的合肥网站建设