当前位置:   article > 正文

html+vue页面请求json文件或接口_vue项目里 html文件怎么请求接口

vue项目里 html文件怎么请求接口

wy_seat_code.json

  1. [
  2. {"name":"杨阿东","num":"1号桌"},
  3. {"name":"王德鹿","num":"2号桌"},
  4. {"name":"徐勇飞","num":"3号桌"},
  5. {"name":"蔡新飞","num":"4号桌"},
  6. {"name":"王珠珠","num":"5号桌"},
  7. ]

页面引用wy_seat_code.json的内容

  1. <!DOCTYPE html>
  2. <html>
  3. <link>
  4. <meta charset="utf-8">
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  7. <meta http-equiv="pragma" content="no-cache">
  8. <meta http-equiv="cache-control" content="no-cache">
  9. <meta http-equiv="expires" content="0">
  10. <title>本地json文件使用</title>
  11. <style>
  12. .dialog-title {
  13. font-size: .4rem;
  14. font-weight: 700;
  15. color: #31302C;
  16. line-height: .4rem;
  17. margin-bottom: 1.05rem;
  18. }
  19. .dialog-cont {
  20. padding: 0 .7rem;
  21. }
  22. .dialog-input {
  23. position: relative;
  24. }
  25. .dialog-input img {
  26. position: absolute;
  27. width: .36rem;
  28. left: .24rem;
  29. }
  30. .dialog-input input {
  31. width: 100%;
  32. display: block;
  33. outline: none;
  34. height: .85rem;
  35. background-color: #F8F9FB;
  36. border-radius: .15rem;
  37. font-size: .24rem;
  38. border: none;
  39. color: #000;
  40. box-sizing: border-box;
  41. padding-left: .77rem;
  42. background-size: .36rem .36rem;
  43. background-position: .24rem center;
  44. }
  45. .dialog-input input::-webkit-input-placeholder {
  46. color: rgba(152, 167, 185, 1);
  47. }
  48. .btn-box {
  49. padding: .56rem 0 .77rem;
  50. }
  51. .com-btn {
  52. width: 100%;
  53. font-size: .28rem;
  54. font-weight: 500;
  55. line-height: .27rem;
  56. text-align: center;
  57. padding: .3rem 0;
  58. border-radius: .15rem;
  59. }
  60. .search-btn {
  61. background-color: rgba(0, 100, 255, 1);
  62. color: #fff;
  63. }
  64. .cancel-btn {
  65. margin-top: .24rem;
  66. background-color: rgba(244, 246, 249, 1);
  67. color: rgba(36, 46, 66, 0.8);
  68. }
  69. </style>
  70. <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  71. </head>
  72. <body>
  73. <div id="app" v-cloak>
  74. <van-dialog v-model="showSeatDialog" title="" get-container="body" :show-confirm-button="false">
  75. <div class="dialog-title" slot="title">座位信息查询</div>
  76. <div class="dialog-cont">
  77. <div class="dialog-input flex-center-center">
  78. <img
  79. src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAMAAABiM0N1AAAAAXNSR0IArs4c6QAAAbNQTFRFAAAAgICAVVVVQEBAMzNmVVVVOTlVMzNNRkZGQEBAOzs7NzdJMzNEPDw8NjZDMzNAMT09Ojo6NzdDNTVANTU+MzM7NjY+NTU8MDc+NjY8NDQ7Mjg+LzU7NDQ6MzM+MDU6NDQ5MTY7MDU6LzQ9MTY6MDU5MDQ9MjY7MjY6MTU5MTU8MDM6MjY5MTQ7LzY8MDU7LzU6MTQ6MDM7MDU6LzQ5LzQ7MDQ5MTM6LzQ7MTM6MDU5MDQ6LzM6MTU7MDQ6LzM7MDQ6LzM7MTU6MDQ6MDQ5LzM6LzQ6MDQ5MDM6LzM6MDQ7MDM6LzQ5MTQ5MDQ6MDM6MDM6MDQ6MDM5MDQ5MDQ6MDM6MDM5LzQ6LzQ6LzQ5MDQ6MDQ6LzM6MDM6MDQ5MDM6MDQ6LzQ6LzM6MDQ5MDQ5MDQ6MDQ6LzM6LzM5MDQ5LzM5LzM5LzQ6MDQ6MDM6MDM5LzQ6MDQ6MDM5MDM5MDM6MDM5MDM6MDM6LzQ6MDM5LzQ5LzQ5LzM6MDM6MDQ5LzQ5LzM6MDM6MDM5LzQ6LzM6LzM5MDM5MDQ5LzQ6LzM6MDM5MDQ6MDQ6LzM5LzM5LzM5iL0BtAAAAJB0Uk5TAAECAwQFBgkKCwwNDg8RExQVFhcYHR4hIiUmJykrLC0wMTQ1Njk6Oz1CQ0RLTE5RW1xdZGVmZ2ttcXJ0dnx+gIKEh4iJioyNj5CRlJWXmJmam56goaOkpaesrbCxs7S2ubq8vb/AwcXHyMnMzc7P0NHT1NXb3N/g4eLk5+jp6uzt7u/w8vP09fb3+Pr7/P3+hBwF3AAAAfNJREFUGBntwelDi3EAB/DvOraMaFlEwkQ5J0py1CpHrlLGHMPmJiHZEitl1S47vn+ydzzPtuf5Hb3d54OaTdvin3j1bTX3YyZ8eT/09TzP8b/FQDO0HIqyTHKoCeou5Vnp614ocj9hVeunoaTxBS0UTkFFkJbSXZA3SBuJZshqSdLOOGRN0tafDsjZkae9u5DTR4Ff9ZASpcgxSMlSZAQyWih0DzIOUigKGccp9BEyDlAoAhnbKTQNKSmKDENKmCLdkNJLgZ8OSNmWpb0bkHSFttJtkLQ1QTvDkNZLG3EX5F2jpdUOKHA8ooVsD5Q477CqxFGo6k2z0lsv1O0OFmj2va8eWvZML/Of4oeBRmhzdA2HXs4vzIQnznpQU86567C//7xJv7+rzQkVdd2jn1ld6dPokTrI8d5aoa2Vm16ItY5nKJS53gqBgRSlpM7Bjus+pQVdsNQ+RwVz7bDgXaCSBS+qcs9S0awbVTREqCzSgEoXqeECKnjWqGHNg3JT1DKFMp1Fail2wmyMmsZgFqemGEx81OaDUYDaAjAKUVsIRm+o7TWMYtQWg1GG2jIw4ibAaInaEjCaorbbMGp6Rk0PnDBxnHi8TmWLkz5Uqtt3Zmji6bsv8aXkRjZfLJVYoVQs5DZ+Ly/Ov48+vDp4cidq5P0F9oAPUcyETvcAAAAASUVORK5CYII=">
  80. <input type="text" v-model="attendeeName" placeholder="请输入您的姓名查询座位信息" />
  81. </div>
  82. <div class="btn-box">
  83. <div class="com-btn search-btn" @click="handleGetInfo">查询</div>
  84. <div class="com-btn cancel-btn" @click="showSeatDialog = false">取消</div>
  85. </div>
  86. </div>
  87. </van-dialog>
  88. </div>
  89. </body>
  90. //可以使用cdn引入
  91. <script src="https://eventimg.oss-cn-shanghai.aliyuncs.com/micro/common_resources/js/axios-v0.24.0.min.js">
  92. </script>
  93. <script src="https://eventimg.oss-cn-shanghai.aliyuncs.com/micro/common_resources/js/vue-v2.6.14.min.js">
  94. </script>
  95. <script src="https://eventimg.oss-cn-shanghai.aliyuncs.com/micro/common_resources/js/utils.js"></script>
  96. <script src="https://eventimg.oss-cn-shanghai.aliyuncs.com/micro/common_resources/js/vant-v2.12.37.min.js">
  97. </script>
  98. <script>
  99. new Vue({
  100. el: '#app',
  101. data: {
  102. showSeatDialog: true,
  103. attendeeName: '',
  104. },
  105. watch: {},
  106. computed: {},
  107. mounted() {
  108. },
  109. methods: {
  110. handleGetInfo() {
  111. if (!this.attendeeName) {
  112. vant.Notify('请输入您的姓名')
  113. return;
  114. }
  115. axios({
  116. method: 'get',
  117. headers: {
  118. 'Content-Type': 'application/json; charset=utf-8',
  119. },
  120. url: `./js/wy_seat_code.json`, //接口地址(可以是本地json文件也可以是后台返回的接口地址)
  121. }).then(
  122. (res) => {
  123. let {
  124. data,
  125. code
  126. } = res;
  127. if (data) {
  128. let list = data.find(item => item.name === this.attendeeName);
  129. if (list) {
  130. //seat.html为查询结果页,可将姓名(name)与座位(num)由路由带过去到seat.html进行显示
  131. window.location.href =
  132. `./seat.html?name=${list.name}&num=${list.num}`;
  133. } else {
  134. vant.Notify('查询不到您的座位码,请确认姓名无误再重试~')
  135. return;
  136. }
  137. }
  138. },
  139. (err) => {
  140. // console.log(err);
  141. },
  142. );
  143. }
  144. }
  145. })
  146. </script>
  147. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/589039
推荐阅读
相关标签
  

闽ICP备14008679号