小程序能不能动态加载模板文件template.wxml?
发布于 4 年前 作者 weizhao 4224 次浏览 来自 问答
  • 需求的场景描述(希望解决的问题)

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

列表做成模板

引用模板 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 回复

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

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

回到顶部