When if
becomes falsey, the stamped content is hidden but not removed from dom. When if
subsequently becomes truthy again, the content is simply re-shown. This approach is used due to its favorable performance characteristics: the expense of creating template content is paid only once and lazily.
Set the restamp
property to true to force the stamped content to be created / destroyed when the if
condition changes.
简而言之,如果需要移除或新建dom则添加restamp=true属性。如下实例:
<template is="dom-if" if="{{loadDialog}}" restamp=true id="dialogTemplate">
...//中间dom
</template>
如果不添加restamp=true,则loadDialog为true/false时,中间dom只是显示(show)或隐藏(hide),添加restamp=true之后,中间dom会新建(create)或移除(destroy).