微信小程序开发笔记
详情参考: https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/conditional.html
<!-- .html 文件 -->
<!-- length 来自 .js 文件中的 data 变量 -->
<view wx:if="{{length > 5}}"> 1 </view>
<view wx:elif="{{length > 2}}"> 2 </view>
<view wx:else> 3 </view>
详情参考: https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/list.html
<!-- .html 文件 -->
<!-- array 是来自 .js 中的 data 数值型变量,里面的元素类型为 Object类型 Object对象类型形式为:{key:value} 键:值 -->
<!-- 使用 wx:for-item 可以指定数组当前元素的变量名,使用 wx:for-index 可以指定数组当前下标的变量名: -->
<view
wx:for="{{array}}"
wx:for-index="idx"
wx:for-item="itemName"
>
{{idx}}: {{itemName.message}}
</view>
// .js 文件
data: {
array: [{
message: 'foo',
}, {
message: 'bar'
}]
}
详情参考: https://developers.weixin.qq.com/miniprogram/dev/component/button.html
按钮css样式参考: https://www.runoob.com/css3/css3-buttons.html
<!-- .html 文件 -->
<!-- 设置登录按钮,type=的样式类型,bindtap=绑定按键点击事件的响应函数 -->
<!-- button组件的,详情参考:https://developers.weixin.qq.com/miniprogram/dev/component/button.html -->
<button type='primary' bindtap="signIn">登录</button>
// .js 文件
// 点击事件的响应函数写法
signIn(e) {
console.log('用户点击登录按钮')
console.log('打印事件e的详情\t---e:\t', e)
},
详情参考: https://www.runoob.com/css/css-intro.html
/* 微信小程序中的单位
px:
像素,图片采样的基本单位。
Vw:
视窗宽度,1vw等 于窗口宽度的1%
vh:
视窗高度、1wh等于窗口高度的1%
rem:
规定屏幕宽度为20rem,实际.上是把页面按比例分割达到自适应的效果(把页面宽度分成20份)
rpx:
规定屏幕宽度为750rpx,以此来根据屏幕宽度进行自适应。如在iphone6 上,屏幕宽度为375px,共有750个物理像素,则
750rpx=375px=750物理像素,相当于1rpx=0.5px=1物理像素。 */
/* 页面定位
选择器{ position: relative; }
相对定位的特点: (务必记住)
1.它是相对于自己原来的位置来移动的(移动位置的时候参照点是自己原来的位置)。
2.原来在标准流的位置继续占有,后面的盒子仍然以标准流的方式对待它。(不脱标,继续保留原来位置)
选择器{ position: absolute; }
绝对定位的特点: (务必记住)
1.如果没有祖先元素或者祖先元素没有定位,则以浏览器为准定位( Document文档)。
2.如果祖先元素有定位(相对、绝对、固定定位) , 则以最近一级的有定位祖先元素为参考点移动位置。
3.绝对定位不再占有原先的位置。(脱标) */
<!-- .html 文件 -->
<view class='background'>
<!-- 添加背景图片 -->
<image src='../../images/icon/background.jpg' mode='aspectFill'></image>
<!-- 添加背景图片的蒙层 -->
<view></view>
</view>
/* .css 文件 */
/* 背景图片 */
.background>image {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index: -999;
}
/* 背景图片上层的蒙层 */
.background>view {
background-color: rgba(255, 255, 255, 0.15);
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index: -900;
}
<!-- .html 文件 -->
<button
class="building-btn"
size="mini"
bindtap="showBuildingComplex"
>
<image
src='...'
class="building-btn-img"
mode='aspectFit'
></image>
</button>
/* .css 文件 */
/* 建筑物图标按钮 */
.building-btn {
padding: 0;
/*按钮透明*/
background-color: transparent;
/*设置按钮边框*/
border: none;
width: 10vw;
height: 10vh;
}
/* 建筑物图标 */
.building-btn-img {
width: 10vw;
height: 10vh;
}
// app.js
// 全局变量,在每一个文件中都可以用
// 使用时,需要结合先定义var app = getApp(),然后再app.globalData.student引用
this.globalData = {
student: {
_id: '',
password: ''
}
};
// 在其他 .js 文件获取全局变量
var app = getApp()
this.setData({
student: app.globalData.student,
})
详情参考: https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#tabBar
// 在 app.json 中
"tabBar": {
"list": [
{
"pagePath": "",
"text": "",
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "",
"text": "",
"iconPath": "",
"selectedIconPath": ""
}
]
},
// config.js 文件
module.exports = {
"appName": "应用",
"default_scale": 16,
"buildingComplexNameAndIconPath": [],
}
// 在其他 .js 文件中使用 config.js 的数据
// 加载 config.js 文件
const config = require('../../config.js');
// 使用配置文件中的参数
config.default_scale
详情参考: https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html
// .js 文件
// wx.navigateTo,详情参考:https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html
// url传参,详情参考:https://blog.csdn.net/weixin_43970434/article/details/98876750
// 跳转至当前建筑物详情的界面,传递变量名为 building 的参数,传参时变量必须用字符串
// 所以可以在当前界面使用 JSON.stringify() 转化为 JSON 字符串,在目的地界面使用 JSON.parse() 转化为 JavaScript 对象
// JSON.stringify() 方法用于将 JavaScript 值转换为 JSON 字符串
// JSON.parse() 方法将数据转换为 JavaScript 对象
wx.navigateTo({
url: '../detailsBuilding/detailsBuilding?building=' + JSON.stringify(building),
})
},
详情参考: https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/database/init.html
// .js 文件
// 调用云数据库 const db=wx.cloud.database()
const db = wx.cloud.database()
详情参考:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/database/read.html
通过调用集合上的 where 方法可以指定查询条件,再调用 get 方法即可只返回满足指定查询条件的记录,
// .js 文件
db.collection('Site').where({ buildingComplexName: this.data.buildingComplexName }).get().then(res => {
console.log('从云数据库Site数据集中,获得了' + res.data.length + '条数据')
})
详情参考:https://developers.weixin.qq.com/miniprogram/dev/component/map.html#marker
<!-- .html 文件 -->
<map
class="map"
scale="{{defaultScale}}"
longitude='{{longitude}}'
latitude='{{latitude}}'
show-location="{{true}}"
markers="{{markers}}"
polyline="{{polyline_Object}}"
bindmarkertap="detailsBuilding"
bindlabeltap="detailsBuilding"
>
// .js 文件
// 调取云数据库中的Site数据集,
// 查询属性buildingComplexName的值为this.data.building的数据
db.collection('Site').where({ buildingComplexName: this.data.buildingComplexName }).get().then(res => {
console.log('从云数据库Site数据集中,获得了' + res.data.length + '条数据')
// 将云数据库中的相关数据值转换为可用合法的markers值
// 标记点用于在地图上显示标记的位置,详情参考:https://developers.weixin.qq.com/miniprogram/dev/component/map.html#marker
for (let i = 0; i < res.data.length; i++) {
let markObj = {
id: i, // 当前标记点的编号
latitude: res.data[i].latitude, // 当前标记点的维度
longitude: res.data[i].longitude, // 当前标记点的经度
iconPath: markersIconPath, // 当前标记点的图标路径
width: config.iconHeight, // 当前标记点的图标的宽
height: config.iconWidth, // 当前标记点的图标的宽
zIndex: i + 1, // 当前标记点的图标图层
// 当前标记点的标签显示
label: {
content: res.data[i].buildingName, // 当前标记点的标签文字
color: config.iconLabelColor,
fontSize: config.iconLabelFontSize,
anchorX: config.iconLabelAnchorX,
anchorY: config.iconLabelAnchorY,
borderWidth: config.iconLabelBorderWidth,
borderColor: config.iconLabelBorderColor,
borderRadius: config.iconLabelBorderRadius,
bgColor: config.themeColors,
padding: config.iconLabelPadding,
}
}
// 将当前的标记点带加入标记点集合中
this.data.markers.push(markObj)
}
// 更新当前的标记点集合,相当于刷新显示
// 并且将获取到的建筑物群信息赋值给this.data.buildingComplex
this.setData({
markers: this.data.markers,
buildingComplex: res.data
})
console.log("当前获取的标记点详情为:\t---this.data.markers:\t\t\t", this.data.markers, "\n")
console.log("当前获取的建筑群详情为:\t---this.data.buildingComplex:\t", this.data.buildingComplex, "\n")
})
详情参考: https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.startLocationUpdate.html
// .js 文件
// wx.startLocationUpdate,开启小程序进入前台时接收位置消息。详情参考:https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.startLocationUpdate.html
// 注意,需要在 app.json 中配置 "requiredPrivateInfos": ["startLocationUpdate"]
wx.startLocationUpdate({
success: (res) => {
type: 'gcj02',
// wx.onLocationChange,监听实时地理位置变化事件。详情参考:https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html
// 需要配合,移除实时地理位置变化事件的监听函数wx.offLocationChange使用——【 wx.offLocationChange(this.data.locationChangeFn)】。详情参考:https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.offLocationChange.html
// 注意,需要在 app.json 中配置 "requiredPrivateInfos": ["onLocationChange"]
wx.onLocationChange(this.data.locationChangeFn)
console.log('开启小程序进入前台时接收位置消息函数wx.startLocationUpdate的返回值\t---res:\t', res)
},
fail: (err) => {
// 重新获取位置权限
wx.openSetting({
success(res) {
res.authSetting = {
"scope.userLocation": true
}
}
})
reject(err)
}
})
详情参考: https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/methodDirection

<!-- .html 文件 -->
<map
class="map"
scale="{{defaultScale}}"
longitude='{{longitude}}'
latitude='{{latitude}}'
show-location="{{true}}"
markers="{{markers}}"
polyline="{{polyline_Object}}"
>
// .js 文件
// 位置改变时,执行当前函数,wx.onLocationChange(function listener)的示例代码,详情参考:https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html#%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81
this.data.locationChangeFn = function (res) {
console.log('位置开始改变,获取\t---res:\t', res)
// 实时更新用户当前的位置,也是路线的开始位置,即start_address
// 同时将用户当前的位置设置为地图的中心位置
that.setData({
latitude: res.latitude,
longitude: res.longitude,
default: 20,
start_address: {
longitude: res.longitude,
latitude: res.latitude
}
})
console.log('获取起始位置为\t---that.data.start_address:\t', that.data.start_address)
console.log('获取终点位置为\t---that.data.end_address:\t', that.data.end_address)
// 使用腾讯位置服务,调用距离计算接口
// 详情参考:https://lbs.qq.com/service/webService/webServiceGuide/webServiceRoute#3
// 以及以下网页,特别是其中的‘Javascript 关键代码片段(驾车、步行、骑行路线规划):’:https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/methodDirection
qqmapsdk.direction({
// 路线规划选择
mode: 'walking',
// 起始位置坐标,采用Object格式
from: {
latitude: that.data.start_address.latitude,
longitude: that.data.start_address.longitude
},
// 终点位置坐标,采用Object格式
to: {
latitude: that.data.start_address.latitude,
longitude: that.data.end_address.longitude
},
// // 用于测试的几组数据,不用看
// from: {
// latitude: 29.9781013308885,
// longitude: 103.000237941741
// },
// to: {
// latitude: 29.9774832826657,
// longitude: 102.993076443672
// },
success: function (res) {
console.log('\n开始规划路线');
console.log('调用距离计算接口qqmapsdk.direction的返回值\t---res:\t', res);
// res.status状态码,正常为0
if (res.status == 0) {
// 解压路线坐标点串
let coors = res.result.routes[0].polyline;
for (let i = 2; i < coors.length; i++) {
coors[i] = coors[i - 2] + coors[i] / 1000000
}
console.log('路线坐标点串解压完毕!路线坐标点串解压结果如下:\c---oors:', coors)
// 将解压后的坐标点串进行拼接成polyline想要的样子
var coors_new = []
for (var j = 0; j < coors.length; j++) {
coors_new.push({
latitude: parseFloat(coors[j]),
longitude: parseFloat(coors[j + 1])
})
j++;
}
// 更新路线
that.setData({
polyline_Object: [{
points: coors_new,
color: "#3FB837",
width: 5,
dottedLine: false
}]
})
}
console.log('当前的路线为:\t---that.polyline_Object:\t', that.data.polyline_Object);
},
fail: function (res) {
console.log('调用路线规划函数失败\t---res:\t', res);
},
complete: function (res) {
console.log('调用路线规划函数结束\t---res:\t', res);
}
});
}
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm
我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
目录前言滤波电路科普主要分类实际情况单位的概念常用评价参数函数型滤波器简单分析滤波电路构成低通滤波器RC低通滤波器RL低通滤波器高通滤波器RC高通滤波器RL高通滤波器部分摘自《LC滤波器设计与制作》,侵权删。前言最近需要学习放大电路和滤波电路,但是由于只在之前做音乐频谱分析仪的时候简单了解过一点点运放,所以也是相当从零开始学习了。滤波电路科普主要分类滤波器:主要是从不同频率的成分中提取出特定频率的信号。有源滤波器:由RC元件与运算放大器组成的滤波器。可滤除某一次或多次谐波,最普通易于采用的无源滤波器结构是将电感与电容串联,可对主要次谐波(3、5、7)构成低阻抗旁路。无源滤波器:无源滤波器,又称
前言一般来说,前端根据后台返回code码展示对应内容只需要在前台判断code值展示对应的内容即可,但要是匹配的code码比较多或者多个页面用到时,为了便于后期维护,后台就会使用字典表让前端匹配,下面我将在微信小程序中通过wxs的方法实现这个操作。为什么要使用wxs?{{method(a,b)}}可以看到,上述代码是一个调用方法传值的操作,在vue中很常见,多用于数据之间的转换,但由于微信小程序诸多限制的原因,你并不能优雅的这样操作,可能有人会说,为什么不用if判断实现呢?但是if判断的局限性在于如果存在数据量过大时,大量重复性操作和if判断会让你的代码显得异常冗余。wxswxs相当于是一个独立
项目介绍随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱小学生兴趣延时班预约小程序的设计与开发被用户普遍使用,为方便用户能够可以随时进行小学生兴趣延时班预约小程序的设计与开发的数据信息管理,特开发了小程序的设计与开发的管理系统。小学生兴趣延时班预约小程序的设计与开发的开发利用现有的成熟技术参考,以源代码为模板,分析功能调整与小学生兴趣延时班预约小程序的设计与开发的实际需求相结合,讨论了小学生兴趣延时班预约小程序的设计与开发的使用。开发环境开发说明:前端使用微信微信小程序开发工具:后端使用ssm:VU