host

一个多页面隐藏切换的组件,比如tab组件,会把内部的元素作为子页面,子页面填充满

属性 作用
page 当前显示那一页

事件

名称 触发时机
load 子元素加载完毕触发(注意:必须写在第一级子元素上)
show 子元素显示时触发(注意:必须写在第一级子元素上)

Demo

  1. <template>
  2. <div style="flex: 1;background-color: #ffffff">
  3. <host style="flex: 1" @change="onchange" :page="index">
  4. <!--<child style="background-color: red;display: flex">-->
  5. <div @load="load" @show="show" style="position: absolute;left: 0;top: 0;right: 0;bottom: 0;background-color: red;">
  6. <div style="flex: 1;background-color: #0085ee;justify-content: center;align-items: center">
  7. <text style="font-size: 55">页面1</text>
  8. <text>目前必须用2div包裹才能保证填充满</text>
  9. <text>第一层的样式必须是position: absolute;left: 0;top: 0;right: 0;bottom: 0;</text>
  10. <text>第二层的样式必须是flex:1</text>
  11. </div>
  12. </div>
  13. <div style="position: absolute;left: 0;top: 0;right: 0;bottom: 0;background-color: red;">
  14. <div style="flex: 1;background-color: #0085ee;justify-content: center;align-items: center">
  15. <text style="font-size: 55">页面2</text>
  16. <text>目前必须用2div包裹才能保证填充满</text>
  17. <text>第一层的样式必须是position: absolute;left: 0;top: 0;right: 0;bottom: 0;</text>
  18. <text>第二层的样式必须是flex:1</text>
  19. </div>
  20. </div>
  21. <div style="position: absolute;left: 0;top: 0;right: 0;bottom: 0;background-color: red;">
  22. <div style="flex: 1;background-color: #0085ee;justify-content: center;align-items: center">
  23. <text style="font-size: 55">页面3</text>
  24. <text>目前必须用2div包裹才能保证填充满</text>
  25. <text>第一层的样式必须是position: absolute;left: 0;top: 0;right: 0;bottom: 0;</text>
  26. <text>第二层的样式必须是flex:1</text>
  27. </div>
  28. </div>
  29. <div style="position: absolute;left: 0;top: 0;right: 0;bottom: 0;background-color: red;">
  30. <div style="flex: 1;background-color: #0085ee;justify-content: center;align-items: center">
  31. <text style="font-size: 55">页面4</text>
  32. <text>目前必须用2div包裹才能保证填充满</text>
  33. <text>第一层的样式必须是position: absolute;left: 0;top: 0;right: 0;bottom: 0;</text>
  34. <text>第二层的样式必须是flex:1</text>
  35. </div>
  36. </div>
  37. </host>
  38. <div style="height: 100;width: 750;position: absolute;bottom: 0;left: 0;right: 0;flex-direction: row;background-color: #0088fb">
  39. <div @click="change(0)" style="flex: 1;align-items: center;justify-content: center">
  40. <text>推荐</text>
  41. </div>
  42. <div @click="change(1)" style="flex: 1;align-items: center;justify-content: center">
  43. <text>电视剧</text>
  44. </div>
  45. <div @click="change(2)" style="flex: 1;align-items: center;justify-content: center">
  46. <text>电影</text>
  47. </div>
  48. <div @click="change(3)" style="flex: 1;align-items: center;justify-content: center">
  49. <text>收藏</text>
  50. </div>
  51. </div>
  52. <!--<prerender src="home.js"></prerender>-->
  53. <!--<prerender src="app/busi/tab/serial.js"></prerender>-->
  54. <!--<a href="demo/pagedemo.js" style="width: 100;height: 100;background-color: red;justify-content: center;align-items: center"><text>跳转</text></a>-->
  55. </div>
  56. </template>
  57. <style>
  58. </style>
  59. <script>
  60. export default {
  61. components:{},
  62. data(){
  63. return {
  64. logoUrl: 'http://img1.vued.vanthink.cn/vued08aa73a9ab65dcbd360ec54659ada97c.png',
  65. target: 'World',
  66. index:0,
  67. }
  68. },
  69. methods: {
  70. onchange(p){
  71. this.toast(p.index)
  72. },
  73. update: function (e) {
  74. this.target = 'Weex'
  75. console.log('target:', this.target)
  76. },
  77. change(i)
  78. {
  79. this.index=i;
  80. },
  81. show()
  82. {
  83. var modal=weex.requireModule("modal")
  84. var p=weex.config.env.osVersion
  85. // p=p.replace('.', "")
  86. // p=p.replace(/./g,"");
  87. p= p.replace(/\./g,'')
  88. modal.alert({message:p})
  89. }
  90. }
  91. ,
  92. created:function(){
  93. var globalEvent = weex.requireModule('globalEvent') ;
  94. var self=this;
  95. globalEvent.addEventListener("onPageInit", function (e) {
  96. const page = weex.requireModule('page');
  97. page.closeSplash();
  98. });
  99. },
  100. }
  101. </script>