首页 > 编程语言 >小程序共享数据2 - 代码实例

小程序共享数据2 - 代码实例

时间:2022-09-23 11:16:10浏览次数:45  
标签:.. 代码 recommendSongInfo value 实例 recommendStore 共享 handleRecommendSongs store


import { HYEventStore } from "hy-event-store" import { getPlaylistDetail } from "../services/music" const recommendStore = new HYEventStore({ state: { recommendSongInfo: {} }, actions: { fetchRecommendSongsAction(ctx) { getPlaylistDetail(3778678).then(res => { ctx.recommendSongInfo = res.playlist }) } } }) export default recommendStore

 

引入  store
import recommendStore from "../../store/recommendStore"


数据
recommendSongs: [],

 // 发起action  网络请求
 recommendStore.dispatch("fetchRecommendSongsAction")

//简单store 的  recommendSongInfo 数组
 recommendStore.onState("recommendSongInfo", this.handleRecommendSongs)


  // ====================== 从Store中获取数据 ======================
// recommendSongInfo 数组 得到的数据 更新当前的数据
  handleRecommendSongs(value) {
    if (!value.tracks) return
    this.setData({ recommendSongs: value.tracks.slice(0, 6) })
  },

//切换页面 , 取消监听
recommendStore.offState(this.handleRecommendSongs)
 

 

标签:..,代码,recommendSongInfo,value,实例,recommendStore,共享,handleRecommendSongs,store
From: https://www.cnblogs.com/qd-lbxx/p/16721965.html

相关文章

  • awk一行代码将平面在极折赤平投影上
    awk一行代码在极折赤平投影上画平面最近用gmt6在极折赤平投影上投点和线的时候遇到了一些问题,于是把脚本贴上来。输入的三列数据为平面的法向量坐标gmtbegintestpng......
  • 小程序共享数据 - 代码实例
    //1.引入storeconst{HYEventStore}=require("hy-event-store")//引入axiosconstaxios=require("axios")//创建一个仓库constuserStore=newHYEventSt......
  • 博客园MarkDown 代码块样式修改
    1.下载样式您可以选择你需要的语言,我直接默认下载了2.查看样式效果这是我使用的样式3.使用样式解压下载的文件,打开你要是使用的样式文件,复制里面的内容直接复制到此......
  • 实例87 拉格朗日插值
    #include<stdio.h>#include<stdlib.h>#include<malloc.h>doubleLAG(int,double*,double*,double);voidmain(){intn;double*x,*y,t,lag;......
  • 实例88 最小二乘法拟合
    #include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<math.h>Smooth(double*,double*,double*,int,int,double*,double*,double*);......
  • 实例89 辛普生数值积分
    #include<stdio.h>#include<math.h>doubleFunction(double);doubleSIMP1(double,double,int);doubleSIMP2(double,double,double);voidmain(){doubl......
  • 实例90 改进欧拉法
    #include"stdio.h"#include"stdlib.h"#include<math.h>intFunc(y,d)doubley[],d[];{d[0]=y[1];/*y0'=y1*/d[1]=-y[0];/*y1'=y0*......
  • 实例92 高斯消去法
    #include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<math.h>intGS(int,double**,double*,double);double**TwoArrayAlloc(int,int);voidTwo......
  • 实例91 龙格-库塔法
    #include"stdio.h"#include"stdlib.h"voidRKT(t,y,n,h,k,z)intn;/*微分方程组中方程的个数,也是未知函数的个数*/intk;/*积......
  • 实例84 二分法求解方程
    #include<stdio.h>#include<math.h>#include<malloc.h>#include<stdlib.h>doubleFunc(double);intBisectRoot(double,double,double,double,double*,int,in......