当前位置:网站首页>Accumulation of applet knowledge points
Accumulation of applet knowledge points
2022-04-23 15:41:00 【Roydly】
uniiapp Some information about wechat payment
methods:{
// Define the event of clicking to place an order
async startPay(){
// Structure and send a request for payment
let {pay_data} = await uni.$axios.request({
url:'xxxxxxxxx',// Address
method:'get',// The way
data:{
orderId:this.query.id// It's related to id
}
})
// After sending the request call requestPayment Method will automatically wake up payment
uni.requestPayment({
// According to the demand All required items of wechat should be filled in
provider:'wxpay',
timeStamp:'',
nonceStr:'',
package:'',
signType:'',
paySign:'',
success:res=> {
uni.navigateTo({
url:'' // Where to successfully jump
})
},
fail:err=> {
console.log(err);
uni.navigateTo({
url:''// Where does failure jump to
})
}
})
}
}
Wechat applet
The main way of parent-child communication
① Attribute binding ( Father and son )
It is used for the parent component to set data to the specified properties of the child component , You can only set JSON Compatible data ( Only data can be passed , Cannot pass method )
// Paternal JS
data:{
count:1 // Data in the parent component
}
<!-- Paternal wxml-->
<view>
<myTest02 count="{
{count}}"></myTest02>
<view> The data passed by the parent component is :{
{count}}</view>
</view>
The subcomponent is in properties Declare the corresponding attribute in the node and use
<!-- Subcomponents wxml-->
<view>{
{count}}</view>
// Subcomponents JS
Component({
// A list of properties of a component
properties:{
count:{
type:Number,
value:0
}
}
})
② Event binding ( Son and father )
Used by child components to pass data to parent components , You can pass any data ( Including arrays and methods )
Implementation steps
Event binding is used to pass values from child to parent , It can deliver Any kind of The data of . The procedure is as follows :
① stay ** Parent component Of js** in , Define a function , This function will be in the form of custom events , Pass to subcomponent
② stay ** Parent component Of wxml** in , In the form of custom events , Will step 1 Function reference defined in , Pass to subcomponent
③ stay Child components js in , By calling this.triggerEvent(' Custom event name ', {/* Parameter object */}), Send data to parent component
④ In the parent component of js in , adopt **e.detail** Get the data passed from the sub component
// step 1: In the parent component of js in , Define a function , This function will be in the form of custom events , Pass to subcomponent
// Parent component JS
Page({
// Define callback function
changeCount(e){
console.log(' Trigger ')
}
})
// step 2: In the parent component of wxml in , In the form of custom events , take step 1 Function reference defined in , Pass to subcomponent
<!-- Paternal wxml-->
<!-- Use bind: Custom event name ( recommend : The structure is clear )-->
<myTest02 count="{
{ count }}" bind:event="changeCount"></myTest02>
<!-- Or in the bind Write the custom name directly behind -->
<myTest02 count="{
{ count }}" bindevent="changeCount"></myTest02>
// step 3: stay Subcomponents js in , By calling this.triggerEvent(' Custom event name ', {/* Parameter object */}), Send data to parent component
<!-- Son of wxml-->
<view>
<button bindtap="setData"> Pass values to the parent component </button>
</view>
// Son of JS
Component({
// Component initial data
data:{
age:10
},
// Component method list
methods:{
setDate(){
this.triggerEvent('event',{age:this.data.age})
}
}
})
step 4: In the parent component of js in , adopt e.detail Get the data passed from the sub component
// Parent component JS
Page({
// Define callback function
changeCount(e){
// Get the data passed by the sub component
console.log(e.detail.age)
}
})
③ Get component instance ( Father and son )
The parent component can also use this.selectComponent() Get the sub component instance object, so you can directly access any data and methods of the sub component
Can be called in the parent component this.selectComponent("id or class Selectors "), Get the instance object of the subcomponent , To directly access any of the subcomponents Semantic data and methods . When calling, you need to pass in a selector , for example this.selectComponent(".my-component")
<!-- Paternal wxml-->
<view>
<!-- Use bind: Custom event name ( recommend : The structure is clear )-->
<myTest02 count="{
{ count }}" id="box" class="box" bind:event="changeCount"></myTest02>
<button bindtap="getSonObj"> Get subcomponent instance </button>
</view>
// Paternal JS
Page({
getSonObj(){
// Bear in mind : The label of the selector cannot be passed , Otherwise, the return is null
// const child = this.selectComponent('.box')
const child = this.selectComponent('#box')
console.log(child)
}
})
版权声明
本文为[Roydly]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231533385994.html
边栏推荐
- APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
- One brush 313 sword finger offer 06 Print linked list from end to end (E)
- mysql乐观锁解决并发冲突
- s16.基于镜像仓库一键安装containerd脚本
- 幂等性的处理
- 大型互联网为什么禁止ip直连
- utils.DeprecatedIn35 因升级可能取消,该如何办
- 开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK
- The El tree implementation only displays a certain level of check boxes and selects radio
- How to test mobile app?
猜你喜欢

使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群

携号转网最大赢家是中国电信,为何人们嫌弃中国移动和中国联通?

mysql乐观锁解决并发冲突

Codejock Suite Pro v20. three

服务器中毒了怎么办?服务器怎么防止病毒入侵?

时序模型:门控循环单元网络(GRU)

G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction

Why is IP direct connection prohibited in large-scale Internet

Modèle de Cluster MySQL et scénario d'application

c语言---指针进阶
随机推荐
How did the computer reinstall the system? The display has no signal
通过 PDO ODBC 将 PHP 连接到 MSSQL
一刷313-剑指 Offer 06. 从尾到头打印链表(e)
一刷314-剑指 Offer 09. 用两个栈实现队列(e)
Extract non duplicate integers
一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
For examination
Go语言数组,指针,结构体
Crawling fragment of a button style on a website
php函数
cadence SPB17. 4 - Active Class and Subclass
大型互联网为什么禁止ip直连
PHP 的运算符
现在做自媒体能赚钱吗?看完这篇文章你就明白了
s16. One click installation of containerd script based on image warehouse
服务器中毒了怎么办?服务器怎么防止病毒入侵?
Cookie&Session
Upgrade MySQL 5.1 to 5.611
如果conda找不到想要安装的库怎么办PackagesNotFoundError: The following packages are not available from current
Independent operation smart farm Innovation Forum