Axios回调函数中的this已经失效,无法直接访问data中的数据,我们可以把this保存起来,回调函数中直接访问保存起来的this(var that = this,回调函数中直接访问that)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<button type="button" @click="getJoke">获取笑话</button>
<p>{{joke}} </p>
</div>
<script>
const app = new Vue({
el: "#app",
data: {
joke: "",
},
meth