wxs 和 template之前的话博主没有去使用过,如有错误请望评论指出!
wxs官方文档参考
template官方文档参考

template

给每个大的分类定一个template

创建文件

在需要使用template的页面文件夹下创建template文件夹,文件夹下面创建title.wxml

iShot_2022-10-17_16.30.40

编写title.wxml

<!--name属性是模版的名字-->
<template name="title">
<view>{{content}}</view>
</template>

使用

在需要使用的界面导入title.wxml

<!--导入-->
<import src="./templates/title.wxml" />
<!--使用title is属性:声明需要的使用的模板 data属性:模板所需要的 data 传入-->
<template is="title" data="{{content:'李四'}}"></template>

wxs

WXS(WeiXin Script)是小程序的一套脚本语言,结合 WXML,可以构建出页面的结构。

WXS 与 JavaScript 是不同的语言,有自己的语法,并不和 JavaScript 一致。

创建文件

在项目跟目录下创建wxs文件夹 文件夹下面创建price.wxs

iShot_2022-10-17_16.40.50

编写price.wxs

// 价格过滤器
var priceFilter = function(price){
return "¥ "+Number(price).toFixed(2)+" 元";
}

// 价格过滤器,不含¥
var priceFilterNo = function(price){
return Number(price).toFixed(2)+" 元";
}

module.exports = {
priceFilter: priceFilter,
priceFilterNo: priceFilterNo
}

使用

<!--module:当前 <wxs> 标签的模块名。必填字段   src:引用 .wxs 文件的相对路径-->
<wxs src="../../wxs/price.wxs" module="price"></wxs>
<!--使用price.wxs的价格过滤器-->
<view>{{price.priceFilter(item.floor_price)}}</view>