1-1 导入Taro模块

  1. //index.vue
  2. import Taro from '@tarojs/taro'

1-2 Taro request 请求对应http渲染页面

  1. //index.vue
  2. <template>
  3. <view class="index">
  4. <!-- <text>{{ msg }}</text> -->
  5. <view v-for="item of movies" :key="item.id">
  6. <image :src="item.pic" alt=""></image>
  7. {{item.title}}
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import './index.scss';
  13. import Taro from '@tarojs/taro'
  14. export default {
  15. data () {
  16. return {
  17. msg: 'Hello world!',
  18. movies:[]
  19. }
  20. },
  21. mounted () {
  22. Taro.request({
  23. url: 'http://120.55.54.252:6060/api/movie/top250',
  24. data: {
  25. foo: 'foo',
  26. bar: 10,
  27. movies:[]
  28. },
  29. header: {
  30. 'content-type': 'application/json'
  31. }
  32. }).then(res =>
  33. this.movies = res.data.res
  34. )
  35. }
  36. }
  37. </script>