api
api>index.js
import request from '@/utils/request'
export const 接口名= (data) => {
return request('后台接口路径','get')
}
文件名.vue
<template>
<div class="container">
<p>{{this.onething}}</p>//接口调用后引用的地方
</div>
</template>
<script>
import { 接口名} from "(上面那个api文件的路径)";
export default {
data(){
return{
onething: '',
}
},
created() {
this.get接口名();//创建一个,随便起名
},
methods:{
get接口名(){
接口名().then((res) => {
this.onething= res.data;
}
}
}
}
</script>