除了其默認(rèn)的意義,<script>標(biāo)簽支持在頁面的頂級組件中通過 type 屬性定義兩種配置。
- type="data": 配置初始化數(shù)據(jù),這里定義的數(shù)據(jù)會覆蓋定義在<script>中的數(shù)據(jù);
- type="config": 定義配置項。
<script type="data">
/* (可選) 定義初始化數(shù)據(jù) */
</script>
<script type="config">
/* (可選) 定義配置項 */
</script>
定義初始化數(shù)據(jù)
有時,很難在默認(rèn)的<script>標(biāo)簽中維護(hù)巨大的數(shù)據(jù)結(jié)構(gòu)。所以 Weex 允許我們通過 <script type="data"> 標(biāo)簽定義初始化數(shù)據(jù)。在這里定義的數(shù)據(jù)將完全取代默認(rèn)的 <script> 標(biāo)簽中定義的數(shù)據(jù)。
例如:
<script type="data">
module.exports = {
title: 'Alibaba',
date: new Date().toLocaleString()
}
</script>
配置項
Weex 也允許我們通過 <script type="config"> 定義一些配置項,目前,僅只支持配置 downgrade。
downgrade.osVersion
downgrade.appVersion
downgrade.weexVersion
downgrade.deviceModel