<template>
<div class="hello">
<div>
{{title}}
</div>
<hr>
<button @click="convert">点击获取数据</button>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: 'HelloWorld',
data() {
return {
title: "静态数据"
}
},
//在这里调用ajax请求方法
created(){
this.convert();
},
methods: {
convert: function () {
axios.get("api/sysUser/getSomething").then(res => {
this.title = res.data;
})
}
}
}
</script>
Vue如何让页面加载时请求后台接口数据
于 2019-01-30 16:56:43 首次发布
本文介绍如何在Vue.js项目中通过Axios库进行数据请求,展示了一个简单的示例,包括在模板中显示静态数据,并在组件创建时通过Ajax请求动态更新数据。

1万+

被折叠的 条评论
为什么被折叠?



