跨域请求测试

📅 2026/7/27 16:38:54 👁️ 阅读次数 📝 编程学习
跨域请求测试

添加代码

<!DOCTYPE html>

<html lang="zh-CN">

<head>

<meta charset="UTF-8">

<title>Vue GET 请求测试</title>

</head>

<body>

<div id="app">

<h3>请求结果:</h3>

<pre>{{ info }}</pre>

</div>

<!-- 引入 Vue 和 Axios -->

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

<script>

new Vue({

el: "#app",

data: {

info: null

},

mounted() {

// 发送 GET 请求

axios.get("https://jsonplaceholder.typicode.com/posts/1")

.then(res => {

console.log("请求成功", res.data);

this.info = res.data;

})

.catch(err => {

console.error("请求失败", err);

});

}

});

</script>

</body>

</html>