Skip to content
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

模板中使用filters和methods #100

Closed
nyrf opened this issue Mar 28, 2019 · 5 comments
Closed

模板中使用filters和methods #100

nyrf opened this issue Mar 28, 2019 · 5 comments

Comments

@nyrf
Copy link

@nyrf nyrf commented Mar 28, 2019

试了下,好像不支持filters?

@beatles-chameleon

This comment has been minimized.

Copy link
Collaborator

@beatles-chameleon beatles-chameleon commented Mar 29, 2019

是的,请使用computed指令代替 https://cmljs.org/doc/logic/computed.html

@nyrf

This comment has been minimized.

Copy link
Author

@nyrf nyrf commented Mar 30, 2019

是的,请使用computed指令代替 https://cmljs.org/doc/logic/computed.html
computed不能传参的,比如我有一组件,

<image src="{{imageUrl}}" />

比如这样,我现在要根据传的参数显示图片尺寸, 在web中使用methods中的方法就可以,但测试了,小程序中不能用,只有web是可以工作

methods : {
  formatUrl (url, style) {
    if (style ===  'small')  { 
       return url + '!small'
    } else {
       return url + '!large'
    }
  }
}
<image src="{{formatUrl(imageUrl, 'small')}}" />

这个时候是不是没办法了?

@nyrf nyrf changed the title 模板中使用filters 模板中使用filters和methods Mar 30, 2019
@nyrf

This comment has been minimized.

Copy link
Author

@nyrf nyrf commented Apr 3, 2019

@beatles-chameleon 请问下后面会支持模板中使用methods和filters么?

@beatles-chameleon

This comment has been minimized.

Copy link
Collaborator

@beatles-chameleon beatles-chameleon commented Apr 4, 2019

@beatles-chameleon 请问下后面会支持模板中使用methods和filters么?

解决方案:
1、如果这个url全局公用且动态变化的则写2个 computed
2、如果这是一个list里面的数据,则在逻辑层先格式化拼装需要的数据格式

思考:
我们认为dsl模板层只用来拼装界面结构的代码,方法逻辑调用应该都在js逻辑层处理,所以只支持computed (逻辑写在js层)映射最终数据到dsl模板层。

cml是考虑真正跨所有端的框架,所以只保留必要的设计,不做过多语法糖,避免影响扩展性(例如以后支持flutter这类终端)。

@nyrf

This comment has been minimized.

Copy link
Author

@nyrf nyrf commented Apr 4, 2019

@beatles-chameleon 请问下后面会支持模板中使用methods和filters么?

解决方案:
1、如果这个url全局公用且动态变化的则写2个 computed
2、如果这是一个list里面的数据,则在逻辑层先格式化拼装需要的数据格式

思考:
我们认为dsl模板层只用来拼装界面结构的代码,方法逻辑调用应该都在js逻辑层处理,所以只支持computed (逻辑写在js层)映射最终数据到dsl模板层。

cml是考虑真正跨所有端的框架,所以只保留必要的设计,不做过多语法糖,避免影响扩展性(例如以后支持flutter这类终端)。

感谢解释,了解

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.