Should my <script> be inside my <dom-module>?

﹥>﹥吖頭↗ 提交于 2019-12-11 00:28:38

问题


I've been developing with polymer and I've always put my <script> tags inside my <dom-module> tags. E.G:

<dom-module id="">
  <template>
    <style>
    </style>

  </template>
  <script>
    Polymer({});
  </script>
</dom-module>

But I've also seen the <script> tags put outside of the <dom-module> tags. E.G:

<dom-module id="">
  <template>
    <style>
    </style>

  </template>
</dom-module>
<script>
  Polymer({});
</script>

Both ways seem to work fine. Which way is considered correct though? Can you explain?


回答1:


The dom-module exists primarily so that the Polymer() call can locate template, style, and other dom resources that belong to a registration. The script itself can live anywhere (as long as the corresponding dom-module exists a priori).

Folks typically put the script inside the module as it provides a tidy bundle, but it remains optional.



来源:https://stackoverflow.com/questions/35808629/should-my-script-be-inside-my-dom-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!