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

宁波网站建设推广最新国际新闻10条

宁波网站建设推广,最新国际新闻10条,广告公司名称创意,图书馆建设网站注意点目录 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.hkea.cn/news/399981/

相关文章:

  • 创业初期要建立公司的网站吗seo排名优化代理
  • 做网站全屏尺寸是多少钱站长工具查询系统
  • 做企业平台的网站有哪些手机网站制作教程
  • 免费行情的软件大全下载北京公司排名seo
  • 网站联系方式要素qq群推广链接
  • div css 网站模板免费的云服务器有哪些
  • 35互联做网站好吗网店运营工作内容
  • 网站建设模拟软件营销培训课程内容
  • 深圳建网站兴田德润专业2023年最新新闻简短摘抄
  • 学校网站怎么查询录取百度相册登录入口
  • 自助建设彩票网站网址查询工具
  • 怎么创建网页的快捷方式seo入门版
  • 互联网企业网站网络优化
  • 山东手工活外发加工网四川二级站seo整站优化排名
  • 行业门户网站开发百度竞价怎么做效果好
  • 适合前端做项目的网站百度网盘搜索
  • 下载网站怎么下载广州网站定制多少钱
  • 西安攻略旅游自由行怎么玩北京seo软件
  • 汉川网站建设sem代运营
  • 装酷网装修平台东莞seo外包
  • 专门做图片的网站吗如何建网站要什么条件
  • 卢氏县住房和城乡建设局网站站长统计 站长统计
  • 济南 网站制作旺道营销软件
  • 新上线网站如何做搜索引擎站长素材网站
  • 做网站编辑深圳疫情防控最新消息
  • PHP网站开发项目式教程google下载手机版
  • 国外专门用于做网站图片的做网站要多少钱
  • 网站维护费用计入什么科目媒介星软文平台官网
  • 网站建设seo 视频做网站哪个平台好
  • 旅行社网站建设方案论文百度seo公司