1、创建页面

  1. taro create --name detail
  1. app.config.js
  2. pages: [
  3. 'pages/index/index',
  4. 'pages/detail/index'
  5. ],

2、引入axios

  1. yarn add axios
  1. //app,js
  2. import axios from 'axios'
  3. Vue.prototype.$http = axios;

3、发送请求

  1. //index.vue
  2. mounted() {
  3. this.$http(`http://47.108.197.28:4000/api/movie/top250`).then((res) => {
  4. this.movies = res.data.res;
  5. });
  6. },

4、路由跳转传值

  1. //index.vue
  2. import Taro from "@tarojs/taro";
  3. goDetail(event) {
  4. // console.log(event);
  5. var { id } = event.target;
  6. // console.log(id);
  7. Taro.navigateTo({
  8. url: `/pages/detail/index?id=${id}`,
  9. });
  10. },
  1. //detail/index.vue
  2. import Taro from "@tarojs/taro";
  3. created() {
  4. this.$instance = Taro.getCurrentInstance();
  5. },
  6. mounted() {
  7. console.log(this.$instance.router.params);
  8. var { id } = this.$instance.router.params;
  9. }