NervJS / taro-plugin-inject

Taro 小程序端平台中间层插件
32 stars 8 forks source link

请问我想在模板想定义一些动态的自定义属性,我该如何做? #14

Open wang-zhixin opened 1 year ago

wang-zhixin commented 1 year ago

官网示例配置:

const config = { plugins: [ ['@tarojs/plugin-inject', { components: { View: { 'data-index': "'dataIndex'" }, ScrollView: { 'data-observe': "'dataObserve'", } } }] ] }

编译后: `

`

这样设置后,每个View上的data-index都是预设的 ‘dataIndex’,但我希望这个dataIndex是代码中动态设置的,请问我该如何做?

wang-zhixin commented 1 year ago

我的需求是在css中伪类的 content: attr(data-xxx) 使用在模板中动态 data-xxx 设置的值

weiaohan commented 1 year ago

官网示例配置:

const config = { plugins: [ ['@tarojs/plugin-inject', { components: { View: { 'data-index': "'dataIndex'" }, ScrollView: { 'data-observe': "'dataObserve'", } } }] ] }

编译后: <View data-index='dataIndex'></View>

这样设置后,每个View上的data-index都是预设的 ‘dataIndex’,但我希望这个dataIndex是代码中动态设置的,请问我该如何做?

您好,请问解决了吗?有同样的问题

RuanLight commented 2 weeks ago

我是编译小程序,可以看一下编译出来的dist文件下base.qml里对应的template(直接搜新增的属性就可以找到),讲道理效果应该类似这样,但我一直编译出来是 data-content="{{i.p0)}}",所以没用,改成这样就可以了⬇️

Text: {
  'data-content': 'i.dataContent'
}

<Text dataContent='test'>