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

做网站公司松江免费seo优化

做网站公司松江,免费seo优化,词条有哪些网站可以做,装饰工程师首先搭建vue3 vite 项目 npm create vue选择pinia 或者自己安装pinia 自己安装需要 npm install pinia并在main.js中挂在上: const pinia createPinia() const app createApp(App) app.use(pinia) app.mount(#app)创建stores文件夹和counter.js文件 counter.j…

首先搭建vue3 vite 项目

npm create vue

选择pinia 或者自己安装pinia

自己安装需要

npm install pinia

并在main.js中挂在上:

const pinia = createPinia()
const app = createApp(App)
app.use(pinia)
app.mount('#app')

创建stores文件夹和counter.js文件

在这里插入图片描述

counter.js中的内容如下:

import { ref, computed } from 'vue'
import { defineStore } from 'pinia'export const useCounterStore = defineStore('counter', () => {const count = ref(0)const other_counts = ref(0)const doubleCount = computed(() => count.value * 2)function increment() {count.value++console.log(count.value)}// 分别设置不同的计时器setInterval(()=>{count.value = count.value+1},1000)// 分别设置不同的计时器setInterval(()=>{other_counts.value = other_counts.value+1}, 3000)// 一定要返回 count, other_counts 不然监听不到return { count, other_counts, doubleCount, increment }
})

在app.vue中进行监听,内容如下:

import {watch} from "vue";
import {useCounterStore} from "@/stores/counter.js";const counter_store = useCounterStore()
// 单独监听store中的某一个属性
watch(()=>counter_store.count, (new_data, old_data)=>{console.log("watch", old_data, new_data)
})// // 监听 store 的状态变化, 即监听store中的所有属性的变化
counter_store.$subscribe((mutation, state) => {console.log("state.count", state.count)console.log("state.other_counts", state.other_counts)
});

页面打印结果如下:

watch 0 1
state.count 1
state.other_counts 0
watch 1 2
state.count 2
state.other_counts 0
watch 2 3
state.count 3
state.other_counts 0
state.count 3                   // 这次输出的3 是因为other_counts的状态发生了变化才输出state.count
state.other_counts 1   
watch 3 4
state.count 4
state.other_counts 1

打印结果分析:

watch监听到store中某一个属性变化后会立即响应,$subscribe方式会监听整个store中的所有属性是否变化,任何一个变化,都会调用$subscribe里的回调函数

$subscribe 也可以这样写:

import {watch} from "vue";
import {useCounterStore} from "@/stores/counter.js";const counter_store = useCounterStore()// watch(()=>counter_store.count, (new_data, old_data)=>{
//   console.log("watch", old_data, new_data)
// })// const websocketMsessage = computed(() => websocketMsessageStore.websocketMsessage);
// // 监听 store 的状态变化
counter_store.$subscribe((mutation, {other_counts}) => {// console.log("state.count", state.count)console.log("state.other_counts",other_counts)
});

打印结果如下:

在这里插入图片描述
再次说明了$subscribe只要监听到store中任何字段的变化都会执行其回调函数

http://www.dtcms.com/wzjs/438221.html

相关文章:

  • 做邮轮的网站交换链接是什么
  • 小米路由HD可以做网站吗网络推广公司专业网络
  • 企业门户网站方案免费广告网
  • 网站建设制作多少钱seo 优化技术难度大吗
  • 网站价值评估 phpseo是什么品牌
  • 为什么电脑打开那个做网站都是那一个百度搜索指数
  • 石柱网站建设关键词分为哪几类
  • 做淘宝用什么批发网站苏州关键词排名系统
  • 专门做校招的网站苏州seo招聘
  • 网站如何设置滚动页面百度怎么发帖做推广
  • 做网站沈阳做推广的软件有哪些
  • 国际新闻大事优化电池充电什么意思
  • 网站建设公司无锡搜索引擎网站推广如何优化
  • 网站页脚导航网站没有友情链接
  • html网站怎么搭建最新国际新闻事件今天
  • wordpress和csdn的区别上海全国关键词排名优化
  • 基层建设期刊网站aso优化app推广
  • 网站的图片做多大尺寸网站生成
  • flash 网站源码郴州seo网络优化
  • 自己做视频网站只能用地址连接专业软文代写
  • 政务网站的建设方案最新天气预报最新消息
  • 温州建设银行官方网站青岛网站seo诊断
  • wordpress 短信验证3天网站seo优化成为超级品牌
  • 免费做网站的网站cpm广告联盟平台
  • 自建站网站产品市场推广方案
  • 品牌网站建设需要哪些规划网站优化外包价格
  • 好看的网站排版站长之家是什么
  • 淘宝购物网站的建设免费涨粉工具
  • 小型企业类网站开发公司网页设计与制作作业成品
  • 北京市运动会网站建设佣金高的推广平台