Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wang-zhixin opened this issue Sep 10, 2022 · 3 comments

Comments

@wang-zhixin
Copy link

官网示例配置:

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是代码中动态设置的,请问我该如何做?

@wang-zhixin
Copy link
Author

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

@weiaohan
Copy link

官网示例配置:

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
Copy link

RuanLight commented Jun 28, 2024

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

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

<Text dataContent='test'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants