微信小程序使用的块

该博客整理了小程序开发中的常用代码块,包括使用block循环、判断if语句、引入template组件模块、不同引入组件方式的效果,以及微信类似js的wxs使用等内容,方便后续开发直接使用,后续还会继续更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

鉴于小程序坑死人不提示的性格,把一些常用的块卸载这里以后方便写的时候直接使用,涉及到路径的都是根据自己工程修改

1、使用block循环

<block wx:for="{{items}}" wx:for-item="item" wx:key ="index">

<view>{{item.name}}</view>

</block>

2、使用判断if语句

<view wx:if="{{condition === 1}}">饺子</view>

<view wx:elif="{{condition === 2}}">米饭</view>

<view wx:else>面食</view>

3、引入template其他组件模块

<import src="/pages/a/a.wxml"></import>

<template is="a">

</template>

在a.wxml中书写

<template name="a">

This is a.wxml

</template>

引入之后我们从父组件传值到子控件可以这样

在index.wxml中

<import src="/pages/a/a.wxml"></import>

<template is="a" data="{{...person}}">

</template>

在父组件index.js中

data: {

person:{

name:'臧三',

phone:'1359923884',

address:'吉林省'

}

}

在子组件中输入样式

<template name="a">

<view>

<view>收件人:{{name}}</view>

<view>联系方式{{phone}}</view>

<view>地址:{{address}}</view>

</view>

</template>

4、引入组件方式不一样产生效果不同

<include src= "a.wxml"/>这种引入是引入的<template></template>之外的内容

<import src="/pages/a/a.wxml"></import>引入的是<template></template>内的内容

5、微信自己类似于js的wxs使用,创建一个index.wxs文件写入

module.exports = {

message:'hello world'

}

再需要的地方写入

<wxs  src = "index.wxs" module = "index" ></wxs>

<view >{{index.message}}</view>

在index.wxs也可以引入另一个wxs

module.exports = require('m1.wxs')

先写到这,继续更新

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值