欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 微信小程序

微信小程序

2024/10/25 14:21:47 来源:https://blog.csdn.net/qq_44627608/article/details/139592152  浏览:    关键词:微信小程序

文章目录

  • 简介
  • index.js
  • index.wxml
  • demo
    • index.js
    • index.wxml


简介

  • 小程序包含一个描述整体程序的app和多个描述各自页面的page
  • 一个小程序主体部由三个文件组成,必须放在根目录
    • app.js主要是小程序的逻辑
    • app.json是小程序公共配置
    • app.wxss是小程序公共样式表

在这里插入图片描述

  • 一个小程序页面由四个文件组成:js、wxml、json和wxss。
  • 其中js(逻辑)和wxml(结构)是必须要有的
  • json页面数据
  • wxss页面样式
    在这里插入图片描述

index.js

// index.js
Page({//定义数据data: {msg1: '我是msg1,我在js中',userName:'',userImage:''},//自定义方法getInfo1() {//wx默认对象,获取用户信息wx.getUserProfile({desc: '获取用户信息',//获取信息success: (res) => {console.log(res.userInfo)//赋值this.setData({userName:res.userInfo.nickName,userImage:res.userInfo.avatarUrl})}})}
})

index.wxml

<!--index.wxml-->
<!-- <navigation-bar title="123" back="{{false}}" color="black" background="#FFF" /> -->
<!-- <scroll-view class="scrollarea" scroll-y type="list"><view class="container">页面内容</view>
</scroll-view> --><view class="container"><view>普通信息:{{msg1}}<br/>用户信息:{{userName}}<br/><image src="{{userImage}}" style="width: 100px;height:100px"></image></view><!--type="primary,default,warn" --><button type="primary" bindtap="getInfo1" >获取用户信息</button></view>

demo

index.js

// index.js
Page({//定义数据data: {msg1: '我是msg1,我在js中',userName: '',userImage: '',//授权码code: ''},//自定义方法getInfo() {//wx默认对象,获取用户信息wx.getUserProfile({desc: '获取用户信息',//获取信息success: (res) => {console.log(res.userInfo)//赋值this.setData({userName: res.userInfo.nickName,userImage: res.userInfo.avatarUrl})}})},//登录,获取授权码login() {wx.login({success: (res) => {console.log(res.code)this.setData({code: res.code})},})},//发送请求sendMsg() {wx.request({url: 'http://localhost:8080/user/shop/status',method: 'GET',success: (res) => {console.log(res.data)}})}
})

index.wxml

<!--index.wxml-->
<!-- <navigation-bar title="123" back="{{false}}" color="black" background="#FFF" /> -->
<!-- <scroll-view class="scrollarea" scroll-y type="list"><view class="container">页面内容</view>
</scroll-view> --><view class="container"><view>普通信息:{{msg1}}<br/>用户信息:{{userName}}<br/><image src="{{userImage}}" style="width: 100px;height:100px"></image></view><!--type="primary,default,warn" --><button type="primary" bindtap="getInfo" >获取用户信息</button>----------------------------------------------<br/><view>只能用一次的授权码:{{code}}</view><button type="warn" bindtap="login" >登录</button>----------------------------------------------<br/><view>发送请求:{{code}}</view><button type="primary" bindtap="sendMsg" >发送请求</button>
</view>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com