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

以cax方式加载svg只能使用renderSvg(htmlsvg,'svg-a',this)这种方式吗? #550

Open
dyj11 opened this issue Apr 14, 2020 · 4 comments

Comments

@dyj11
Copy link

dyj11 commented Apr 14, 2020

let mD = <svg width="300" height="300"> <rect bindtap="tapHandler" x="0" y="0" height="110" width="110" style="stroke:#ff0000; fill: #0000ff" /> <rect bindtap="tapHandler" x="0" y="0" height="110" width="110" style="stroke:#ff0000; fill: #0000ff" /> </svg>;
const svg = renderSVG(html${mD}, 'svg-a', this)
console.log('children:' + svg.children.length)

为什么我使用这种方式加载svg,无法渲染svg。因为项目需要加载外部svg
svgError

@dntzhang
Copy link
Collaborator

dntzhang commented Apr 14, 2020

是的。这样不行,因为这样解不出虚拟节点。https://github.com/developit/htm

需要:

html`<svg>xxxx</svg>`

当然你也可以 hypescript 的方式加载和书写。

h('svg', xxx, xxx)

@dyj11
Copy link
Author

dyj11 commented Apr 14, 2020

是的。这样不行,因为这样解不出虚拟节点。https://github.com/developit/htm

需要:

html`<svg>xxxx</svg>`

当然你也可以 hypescript 的方式加载和书写。

h('svg', xxx, xxx)

请问下,为什么我这样做不行呢?原理是什么呢?还有就是采用hypescript的方式可以在小程序里面使用吗?

@dntzhang
Copy link
Collaborator

@dyj11
Copy link
Author

dyj11 commented Apr 15, 2020

可以深入学习下 template string
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/template_strings

感谢解答

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

2 participants