小程序能不能动态加载模板文件template.wxml?

发布于 6 年前作者 weizhao4449 次浏览最后编辑 6 年前来自 ask
  • 需求的场景描述(希望解决的问题)

小程序同一个页面通过点击按钮切换,显示不同样式的列表

列表做成模板

引用模板 import 不能使用变量,

<import src=“{{tplWhere.tplPath}}” />

<template is=“{{tplWhere.tplName}}” data=“{{tplWhere.tplData}}”/>

报错:

./pages/template/where/where_1.wxml

 Bad attr `data` with message

  1 | <import src=“{{tplWhere.tplPath}}” />

> 2 | <template is=“{{tplWhere.tplName}}” data=“{{tplWhere.tplData}}”/>

    |                                         ^

  3 | <!-- <view>{{tplWhere.tplPath}}</view> –>

  4 | <view style=‘width:100%;’>

  • 希望提供的能力
2 回复
guping
guping1 楼6 年前

我也遇到这个问题了,似乎是因为template中的数据必须和传的的数据一样,你这样写data=“{{tplData:tplWhere.tplData}}”,保证你通过data传进去的对象跟你在template中定义的一样

tao42
tao422 楼4 年前

小程序不支持这种方式引用模板吗?