ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ### 1. 在src下新建models文件,再新建http.js ~~~ import axios from 'axios'; var baseUrl="https://www.easy-mock.com/mock/5bac6e450132334db716717d/test/test"; class HTTP { request({url,method="get",data={},params={}}){ return axios({ url:baseUrl+url, method, data, params }) } } export {HTTP}; ~~~ ### 2. 在models文件新建MovieModel.js再次封装 ~~~ import {HTTP} from "./HTTP"; class MovieModel extends HTTP { getTop250(){ return this.request({ url:"" }) } getComingSoon(){ return this.request({ url:"" }) } } export {MovieModel}; ~~~ ### 3. 在pages下的.vue文件中使用 ~~~ <template> <div class="home"> <p>{{msg}}</p> </div> </template> <script> import {MovieModel} from "../models/MovieModel"; const movieModel = new MovieModel(); export default { name: "Home", data(){ return { msg:"hello world" } }, created(){ movieModel.getTop250().then(res=>{ // console.log(res) var title = res.data.data[0].name; this.msg = title; }) } }; </script> <style lang="scss" scoped> .home { text-align: center; } </style> ~~~