以axios爲例使用外部插件分爲三步ios
npm i axios //到相應目錄下執行該命令 npm
import axios from "axios"axios
使用和之前同樣,該怎麼用仍是怎麼用this
axios({ url:"xxx" }).then(res=>{ })
DEMOurl
<template> <div> <input type="text" v-model="searchValue" /> <button @click="getMusic">點我</button> <ul> <li v-for="(item, index) in songs" :key="index">{{item.name}}</li> </ul> </div> </template> <script> // 使用axios 1:安裝axios,npm i axios 2:導包 import axios from "axios" 3:使用 // 導包 import axios from "axios"; export default { data() { return { searchValue: "", //input框的值 songs: [] }; }, methods: { getMusic() { // 使用,之前怎麼用,如今還怎麼用 axios({ url: "https://autumnfish.cn/search?keywords=" + this.searchValue, method: "get" }).then(res => { this.songs = res.data.result.songs; window.console.log(this.songs); }); } } }; </script> <style> </style>