//模板t1.wxml
<template name="t1">
<view>{{type}}</view>
<block wx:for="{{newsList}}" wx:for-item="{{news}}">
{{news.title}}
</block>
</template>
//index.wxml调用模板t1
<import src="../templates/t1" />
<template is="t1" data="{{newsList,type}}"/> //向模板传递多个值
//index.wxss调用模板样式
@import "../templates/template1.wxss";
//index.js调用模板js,并向模板传值
require('../templates/t1.js') //模板的js不允许出现Page()等页面方法,只允许出现绑定一类的事件
this.setData({
newsList:myNewsList,
type:"新闻类别"
})
微信小程序 template模板的使用
最新推荐文章于 2024-07-06 22:23:57 发布