加载中...

1.2.9 页面配置 & 数据


你可以在另外的<script>中写一些 配置和数据的实例,添加到 top-level weex 组件中。

  • 配置实例中可以申明一些meta信息 比如SDK/Client版本。支持降级到H5 渲染方式。未来还将支持更多的扩展。
  • 数据实例中可以设置外部数据替换掉默认top-level组件数据。

这些都使weex文件更具扩展和可配置,让其更容易的在其他工具和服务中工作,比如CMS系统。

  1. <!-- definition of sub components -->
  2. <element name="sub-component-a">...</element>
  3. <element name="sub-component-b">...</element>
  4. <element name="sub-component-c">...</element>
  5.  
  6. <!-- definition of top-level component -->
  7. <template>...</template>
  8. <style>...</style>
  9. <script>
  10. module.exports = {
  11. data: function () {return {x: 1, y: 2}}
  12. }
  13. </script>
  14.  
  15. <!-- instance config and data -->
  16. <script type="config">
  17. downgrade: {
  18. ios: {
  19. os: '9', // all of 9.x.x
  20. app: '~5.3.2',
  21. framework: '^1.3', // all of 1.3.x
  22. deviceModel: ['AAAA', 'BBBB']
  23. },
  24. android: {
  25. os: '*', // all of version
  26. app: '^5',
  27. framework: '',
  28. deviceModel: ''
  29. }
  30. }
  31. </script>
  32. <script type="data">
  33. {y: 200}
  34. </script>

请注意,这两个附加<script>都是optinal并且有type="config|data" 属性,当它是一个Weex实例的top-level组件才有效。

这是所有关于Weex语法。更多阅读,请查看:


还没有评论.