问题
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