完整示例代码

其实执行到上一步我们已经完成了示例的全部开发步骤。但为了清晰和可读性考虑,我们把最终形态的示例代码展示给开发者。

index.html

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>首页</title>
  5. <meta name="apple-touch-fullscreen" content="yes">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="format-detection" content="telephone=no">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
  9. <link rel="stylesheet" href="https://c.mipcdn.com/static/v2/mip.css">
  10. <style mip-custom>
  11. h1 {
  12. text-align: center;
  13. line-height: 80px;
  14. }
  15. .city {
  16. text-align: center;
  17. line-height: 40px;
  18. }
  19. .next-link {
  20. display: block;
  21. margin: 0 auto;
  22. width: 170px;
  23. text-align: center;
  24. background: #69f;
  25. border-radius: 20px;
  26. height: 40px;
  27. line-height: 40px;
  28. color: white;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <mip-shell>
  34. <script type="application/json">
  35. {
  36. "routes": [
  37. {
  38. "pattern": "/index.html",
  39. "meta": {
  40. "header": {
  41. "show": true,
  42. "title": "我的首页",
  43. "buttonGroup": [
  44. {
  45. "name": "subscribe",
  46. "text": "关注"
  47. },
  48. {
  49. "name": "chat",
  50. "text": "发消息"
  51. }
  52. ]
  53. },
  54. "view": {
  55. "isIndex": true
  56. }
  57. }
  58. },
  59. {
  60. "pattern": "/city-selector.html",
  61. "meta": {
  62. "header": {
  63. "show": true,
  64. "title": "城市选择页"
  65. }
  66. }
  67. }
  68. ]
  69. }
  70. </script>
  71. </mip-shell>
  72. <mip-data>
  73. <script type="application/json">
  74. {
  75. "#city": "上海",
  76. "title": "首页标题"
  77. }
  78. </script>
  79. </mip-data>
  80. <h1 m-text="title"></h1>
  81. <p class="city">选择城市:<span m-text="city"></span></p>
  82. <a mip-link href="./city-selector.html" class="next-link">Go to City Selector Page</a>
  83. <script src="https://c.mipcdn.com/static/v2/mip.js"></script>
  84. </body>
  85. </html>

city-selector.html

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>城市选择页</title>
  5. <meta name="apple-touch-fullscreen" content="yes">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="format-detection" content="telephone=no">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
  9. <link rel="stylesheet" href="https://c.mipcdn.com/static/v2/mip.css">
  10. <style mip-custom>
  11. h1 {
  12. text-align: center;
  13. line-height: 80px;
  14. }
  15. .city {
  16. padding: 20px;
  17. background: rgba(0, 0, 0, .1)
  18. }
  19. .city span {
  20. color: red;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <mip-shell>
  26. <script type="application/json">
  27. {
  28. "routes": [
  29. {
  30. "pattern": "/index.html",
  31. "meta": {
  32. "header": {
  33. "show": true,
  34. "title": "我的首页",
  35. "buttonGroup": [
  36. {
  37. "name": "subscribe",
  38. "text": "关注"
  39. },
  40. {
  41. "name": "chat",
  42. "text": "发消息"
  43. }
  44. ]
  45. },
  46. "view": {
  47. "isIndex": true
  48. }
  49. }
  50. },
  51. {
  52. "pattern": "/city-selector.html",
  53. "meta": {
  54. "header": {
  55. "show": true,
  56. "title": "城市选择页"
  57. }
  58. }
  59. }
  60. ]
  61. }
  62. </script>
  63. </mip-shell>
  64. <mip-data>
  65. <script type="application/json">
  66. {
  67. "title": "城市选择页标题"
  68. }
  69. </script>
  70. </mip-data>
  71. <h1 m-text="title"></h1>
  72. <p class="city">当前选择城市: <span m-text="city"></span></p>
  73. <mip-city-list>
  74. <script type="application/json">
  75. {
  76. "list": [
  77. "北京",
  78. "上海",
  79. "广州",
  80. "深圳",
  81. "成都",
  82. "武汉",
  83. "拉萨",
  84. "南昌",
  85. "杭州",
  86. "苏州",
  87. "南京",
  88. "天津"
  89. ]
  90. }
  91. </script>
  92. </mip-city-list>
  93. <script src="https://c.mipcdn.com/static/v2/mip.js"></script>
  94. <script src="http://somecdn.com/mip-city-list.js"></script>
  95. </body>
  96. </html>

mip-city-list.vue

  1. <template>
  2. <div class="mip-city-list-wrapper">
  3. <p class="sub-header">城市列表:</p>
  4. <ul>
  5. <li
  6. v-for="(item, i) in list"
  7. @click="select(i)">{{item}}</li>
  8. </ul>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. props: {
  14. list: {
  15. default: () => [],
  16. type: Array
  17. }
  18. },
  19. methods: {
  20. select (index) {
  21. MIP.setData({
  22. city: this.list[index]
  23. })
  24. }
  25. }
  26. }
  27. <script>
  28. <style scoped>
  29. .mip-city-list-wrapper {
  30. padding: 20px;
  31. }
  32. .mip-city-list-wrapper ul {
  33. list-style-type: none;
  34. line-height: 28px;
  35. margin-left: 20px;
  36. }
  37. </style>