国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【微信小程序】后臺數(shù)據(jù)交互于WX文件使用

這篇具有很好參考價(jià)值的文章主要介紹了【微信小程序】后臺數(shù)據(jù)交互于WX文件使用。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

目錄

一、前期準(zhǔn)備

1.1 數(shù)據(jù)庫準(zhǔn)備

1.2 后端數(shù)據(jù)獲取接口編寫

1.3 前端配置接口

1.4?封裝微信的request請求

?文章來源地址http://www.zghlxwxcb.cn/news/detail-721451.html

二、WXS文件的使用

2.1 WXS簡介

2.2 WXS使用

?

三、后臺數(shù)據(jù)交互完整代碼

3.1 WXML

3.2 JS

3.3 WXSS

效果圖?


一、前期準(zhǔn)備

1.1 數(shù)據(jù)庫準(zhǔn)備

創(chuàng)建數(shù)據(jù)庫:

注意:字符集選擇utf8mb4,因?yàn)榭赡苡么鎯τ脩粜畔?,而有些用戶包含emoji標(biāo)簽,用該字符集可以進(jìn)行存儲顯示。

【微信小程序】后臺數(shù)據(jù)交互于WX文件使用,微信小程序,java,微信小程序,小程序?

會議表結(jié)構(gòu):?

【微信小程序】后臺數(shù)據(jù)交互于WX文件使用,微信小程序,java,微信小程序,小程序

1.2 后端數(shù)據(jù)獲取接口編寫

package com.ycxw.minoa.wxcontroller;

import com.ycxw.minoa.mapper.InfoMapper;
import com.ycxw.minoa.model.Info;
import com.ycxw.minoa.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Autho 云村小威
 * @Since 2023/10/21
 */
@RestController
@RequestMapping("/wx/home")
public class WxHomeController {
    @Autowired
    private InfoMapper infoMapper;
    @RequestMapping("/index")
    public Object index(Info info) {
        List<Info> infoList = infoMapper.list(info);
        Map<Object, Object> data = new HashMap<Object, Object>();
        data.put("infoList",infoList);
        return ResponseUtil.ok(data);
    }
}

1.3 前端配置接口

創(chuàng)建config文件夾 --> api.js文件:?

// 以下是業(yè)務(wù)服務(wù)器API地址
 // 本機(jī)開發(fā)API地址
 var WxApiRoot = 'http://localhost:8080/wx/';
 // 測試環(huán)境部署api地址
 // var WxApiRoot = 'http://192.168.0.101:8070/wx/';
 // 線上平臺api地址
 //var WxApiRoot = 'https://www.oa-mini.com/wx/';
 
 module.exports = {
   IndexUrl: WxApiRoot + 'home/index', //首頁數(shù)據(jù)接口
 };

1.4?封裝微信的request請求

通過分裝微信request請求減少每次都需編寫重復(fù)的請求代碼:

utils/util.js:?

/**
 * 封裝微信的request請求
 */
function request(url, data = {}, method = "GET") {
  return new Promise(function (resolve, reject) {
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'Content-Type': 'application/json',
      },
      success: function (res) {
        if (res.statusCode == 200) {
            resolve(res.data);//會把進(jìn)行中改變成已成功
        } else {
          reject(res.errMsg);//會把進(jìn)行中改變成已失敗
        }
      },
      fail: function (err) {
        reject(err)
      }
    })
  });
}

module.exports = {
  request
}

二、WXS文件的使用

2.1 WXS簡介

????????WXS(WeiXin Script)是內(nèi)聯(lián)在 WXML 中的腳本段。通過 WXS 可以在模版中內(nèi)聯(lián)少量處理腳本,豐富模板的數(shù)據(jù)預(yù)處理能力。另外, WXS 還可以用來編寫簡單的?WXS 事件響應(yīng)函數(shù)。

從語法上看, WXS 類似于有少量限制的 JavaScript 。要完整了解 WXS 語法,請參考WXS 語法參考。

2.2 WXS使用

1、首先在utils目錄下創(chuàng)建common.wxs,這個(gè)文件存放我們所有的函數(shù)方法

//會議人數(shù)
function getNum(liexize,canyuze,zhuchiren){
  var person = liexize+","+canyuze+","+zhuchiren;
  return person.split(',').length;
}
 
//會議狀態(tài)
function getStateName(state){
  if (state == 1){
    return "待審核"
  }else if (state == 1){
    return "審核通過"
  }else if (state == 1){
    return "審核不通過"
  }else if (state == 1){
    return "待開"
  }
  return "其他";
}

//導(dǎo)出方法
module.exports = {
  getStateName:getStateName,
  getNum:getNum
};

?

2、將它導(dǎo)入綁定到需要使用的WXML中

<wxs src="/utils/common.wxs" module="tools" />

【微信小程序】后臺數(shù)據(jù)交互于WX文件使用,微信小程序,java,微信小程序,小程序

3、通過定義的module屬性值即可調(diào)用方法

<view class="state">{{tools.getStateName(xxx數(shù)據(jù))}}</view>

?【微信小程序】后臺數(shù)據(jù)交互于WX文件使用,微信小程序,java,微信小程序,小程序

三、后臺數(shù)據(jù)交互完整代碼

3.1 WXML

<wxs src="/utils/common.wxs" module="tools" />
<view class="indexbg">
    <swiper autoplay="true" indicator-dots="true" indicator-color="#fff" indicator-active-color="#00f" style="height: 190px;">
        <block wx:for="{{imgSrcs}}" wx:key="text">
            <swiper-item>
                <view>
                    <image src="{{item.img}}" class="swiper-item" />
                </view> 
            </swiper-item>
        </block>
    </swiper>
    <view class="mobi-title">
        <text class="mobi-text">會 議 信 息</text>
    </view>
    <block wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id" class="bg">
        <view class="list" data-id="{{item.id}}">
            <view class="list-img">
                <image class="video-img" mode="scaleToFill" src="{{item.image != null ? item.image : '/static/images/avatar.png'}}"></image>
            </view>
            <view class="list-detail">
                <view class="list-title"><text>{{item.title}}</text></view>
                <view class="list-tag">
                  <view class="state">{{tools.getStateName(item.state)}}</view>
                  <view class="join">
                    <text class="list-num">{{tools.getNum(item.canyuze,item.liexize,item.zhuchiren)}}</text> 人報(bào)名
                  </view>
                </view>
                <view class="list-info"><text>{{item.location}}</text>|<text>{{item.starttime}}</text></view>
            </view>
        </view>
    </block>
    <view class="section">
        <text>到底啦</text>
    </view>
</view>

3.2 JS

// index.js
// 獲取應(yīng)用實(shí)例
const app = getApp()
const api = require("../../config/api")
const util = require("../../utils/util.js")

Page({
    data: {
        imgSrcs: [ {
          "img": "https://1.s91i.faiusr.com/4/AFsI4uYPEAQYACDw69bhBSjulrWKBTDABzicBA!800x800.png?_tm=3&v=1556100764632",
          "text": "1"
        },
        {
          "img": "https://img.zcool.cn/community/01e71e61e7c7ba11013e8cd0236304.jpg?x-oss-process=image/auto-orient,1/resize,m_lfit,w_1280,limit_1/sharpen,100",
          "text": "2"
        },
        {
          "img": "https://ts1.cn.mm.bing.net/th/id/R-C.022f2e37a033ca3c5754d2f32e8132a1?rik=9ysyMcx6nMOilg&riu=http%3a%2f%2fres.picxiaobai.com%2ftxb%2ftemplate%2fpre%2f20200517%2fd7580b5326b45a612dbf2c1904bc6ca2.jpg%3fv%3d1589705812%26x-oss-process%3dimage%2fresize%2cw_500&ehk=mHQV45sPbW8QB5iv%2ftSXZeasTn4bN6d%2bdLOtwiOYpl8%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1",
          "text": "3"
        },
        {
          "img": "https://bpic.588ku.com/Templet_origin_pic/05/08/59/20760ea806f4a490f73c577d69e8ffe8.jpg",
          "text": "4"
        },
        {
          "img": "https://img.tukuppt.com/ad_preview/00/10/75/5d78cd9a6a9b4.jpg!/fw/780",
          "text": "5"
        },
        {
          "img": "https://1.s91i.faiusr.com/4/AFsI4uYPEAQYACDv69bhBSiCruq3BTDABzicBA!800x800.png?v=1556100745578",
          "text": "6"
        }],
        lists: []
    },
    // 事件處理函數(shù)
    bindViewTap() {
        wx.navigateTo({
            url: '../logs/logs'
        })
    },

   //首頁會議信息的ajax
   loadMeetingInfos() {
      util.request(api.IndexUrl).then(res => {
        this.setData({
        lists: res.data.infoList
      })
    })
  },
 
    onLoad() {
        if (wx.getUserProfile) {
            this.setData({
                canIUseGetUserProfile: true
            })
        }

        this.loadMeetingInfos();
    }

})

3.3 WXSS

/**index.wxss**/
.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #aaa;
}

.userinfo-avatar {
  overflow: hidden;
  width: 128rpx;
  height: 128rpx;
  margin: 20rpx;
  border-radius: 50%;
}

.usermotto {
  margin-top: 200px;
}

/**index.wxss**/
.section {
  color: #aaa;
  display: flex;
  justify-content: center;
}

.list-info {
  color: #aaa;
}

.list-num {
  color: red;
  /* font-weight: 700; */
}

.join {
  padding: 0px 0px 0px 10px;
  color: #aaa;
}

.state {
  margin: 3px 6px 0px 0px;
  border: 1px solid #4083ff;
  color: #4083ff;
  padding: 3px 5px 3px 5px;
}

.list-tag {
  padding: 3px 0px 10px 0px;
  display: flex;
  align-items: center;
}

.list-title {
  display: flex;
  justify-content: space-between;
  font-size: 11pt;
  color: #333;
  font-weight: bold;


}

.list-detail {
  display: flex;
  flex-direction: column;
  margin: 0px 0px 0px 15px;
}

.video-img {
  margin-top: 8px;
  width: 90px;
  height: 90px;
}

.list {
  display: flex;
  flex-direction: row;
  background-color: rgb(232, 240, 245);
  border-bottom: 1px solid #ccd1d3;
  padding: 10px;
}

.mobi-text {
  font-weight: 700;
  padding: 15px;
  color: white;
}

/* .mobi-icon {
  border-left: 5px solid #57f564;
} */
.indexbg{
    background-color: rgba(219, 219, 219, 0.678);
}

.mobi-title {
  display: flex;
  align-items: center;
  height: 40px;
  background-color: rgba(69, 147, 250, 0.678);
}

.swiper-item {
  height: 345rpx;
  width: 100%;
  border-radius: 10rpx;
}

.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #aaa;
}

.userinfo-avatar {
  overflow: hidden;
  width: 128rpx;
  height: 128rpx;
  margin: 20rpx;
  border-radius: 50%;
}

.usermotto {
  margin-top: 200px;
}

效果圖?

【微信小程序】后臺數(shù)據(jù)交互于WX文件使用,微信小程序,java,微信小程序,小程序

?

到了這里,關(guān)于【微信小程序】后臺數(shù)據(jù)交互于WX文件使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【微信小程序】6天精準(zhǔn)入門(第5天:利用案例與后臺的數(shù)據(jù)交互)附源碼

    【微信小程序】6天精準(zhǔn)入門(第5天:利用案例與后臺的數(shù)據(jù)交互)附源碼

    ????????在小程序中,與后臺交互指的是小程序前端與后臺服務(wù)器之間的數(shù)據(jù)通信和請求處理過程。通過與后臺交互,小程序能夠獲取服務(wù)器端的數(shù)據(jù)、上傳用戶數(shù)據(jù)、發(fā)送請求等。 ????????小程序與后臺交互可以實(shí)現(xiàn)數(shù)據(jù)的傳輸、用戶認(rèn)證、實(shí)時(shí)消息推送等功能,為

    2024年02月08日
    瀏覽(19)
  • 微信小程序——后臺交互

    微信小程序——后臺交互

    目錄 后臺準(zhǔn)備 pom.xml 配置數(shù)據(jù)源 整合mtbatis 前后端交互 ?method1 ?method2 生成mapper接口、model實(shí)體類以及mapper映射文件 啟動類 然后啟動后臺即可 首先在index.js中編寫以下方法 然后在該頁面下方生命周期函數(shù)——監(jiān)聽頁面加載代碼塊下編寫以下方法 由于后臺是沒有數(shù)據(jù)圖片的,

    2024年02月06日
    瀏覽(24)
  • 微信小程序?yàn)g覽docx,pdf等文件在線預(yù)覽使用wx.openDocument
  • 微信小程序之后臺首頁交互

    微信小程序之后臺首頁交互

    目錄 一.與后臺數(shù)據(jù)進(jìn)行交互request封裝 后臺準(zhǔn)備 測試結(jié)果 ?編輯? ?前端 ?測試結(jié)果 ?二.wxs的介紹以及入門? 測試結(jié)果 后臺準(zhǔn)備 pom.xml文件編寫 建立數(shù)據(jù)表 建立數(shù)據(jù)請求地址類? 定義接口類? 測試結(jié)果 ? ?前端 先關(guān)閉mock ? ?先編寫url地址 ?編寫utils.js 編寫index.js? ?編寫

    2024年02月08日
    瀏覽(22)
  • 微信小程序之網(wǎng)絡(luò)數(shù)據(jù)請求 wx:request的簡單使用

    微信小程序之網(wǎng)絡(luò)數(shù)據(jù)請求 wx:request的簡單使用

    出于安全性方面的考慮,小程序官方對 數(shù)據(jù)接口的請求 做出了兩個(gè)限制: 只能請求 HTTPS 類型的接口必須將接口的域名添加到信任列表中 . 在自己的微信小程序開發(fā)的后臺管理中添加相應(yīng)的服務(wù)器域名,配置步驟: 登錄微信小程序管理后臺 - 開發(fā) - 開發(fā)設(shè)置 - 服務(wù)器域名

    2024年02月16日
    瀏覽(29)
  • 微信小程序進(jìn)階——后臺交互個(gè)人中心授權(quán)登錄

    微信小程序進(jìn)階——后臺交互個(gè)人中心授權(quán)登錄

    目錄 一、小程序登錄微信登錄接口演示 1.1 項(xiàng)目導(dǎo)入 1.2 method1? 1.3 method2 二、小程序授權(quán)登錄 2.1 登錄過程 2.1.1 詳解 2.1.2 圖解 2.2 后端代碼導(dǎo)入 2.3 前端代碼導(dǎo)入 ?編輯 2.4 案例演示 前端代碼如下: 2.4.1 前端調(diào)用接口地址 2.4.2 個(gè)人中心 后端代碼如下: 2.5 效果演示? ? 然后

    2024年02月02日
    瀏覽(25)
  • 微信小程序之會議OA首頁后臺交互

    springboot+mybatis appliation.yml 生成mapper接口,model實(shí)體類,mapper映射文件 application.yml 在啟動類 Promise 是異步編程的一種解決方案,比傳統(tǒng)的解決方案——回調(diào)函數(shù)和事件——更合理和更強(qiáng)大。它由社區(qū)最早提出和實(shí)現(xiàn),ES6 將其寫進(jìn)了語言標(biāo)準(zhǔn),統(tǒng)一了用法,原生提供了Promise對象

    2024年02月20日
    瀏覽(36)
  • 微信小程序之會議OA個(gè)人中心后臺交互

    微信小程序之會議OA個(gè)人中心后臺交互

    目錄 獲取用戶昵稱頭像和昵稱 小程序登錄 登錄-小程序 wx.checkSession wx.login wx.request 后臺 準(zhǔn)備數(shù)據(jù)表 反向生成工具生成 準(zhǔn)備封裝前端傳過來的數(shù)據(jù) 小程序服器配置 導(dǎo)入微信小程序SDK application.yml WxProperties WxConfig WxAuthController 登錄-小程序 login.js user.js util.js emoji wx.getUserProfi

    2024年02月22日
    瀏覽(32)
  • 微信小程序數(shù)據(jù)交互------WXS的使用

    微信小程序數(shù)據(jù)交互------WXS的使用

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 艷艷耶??:個(gè)人主頁 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 個(gè)人專欄 :《Spring與Mybatis集成整合》《Vue.js使用》 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 越努力 ,越幸運(yùn)

    2024年02月05日
    瀏覽(24)
  • 微信小程序同時(shí)上傳多個(gè)文件(wx.uploadFile)

    使用遞歸有一個(gè)問題,如果要上傳的東西里,其余參數(shù)中有些值只能上傳一次,比如日期,在第二次上傳的時(shí)候會顯示此日期已經(jīng)添加,請勿重復(fù)添加,這樣就會導(dǎo)致只上傳成功第一個(gè)文件。 Multipart.min.js提取鏈接: 鏈接:提取Multipart.min.js 提取碼:xxqd

    2024年02月03日
    瀏覽(89)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包