// v-model实现表单数据searchKeyword的双向绑定
// @keydown.enter表示回车执行saveKeyWord方法
<input type="text" v-model="searchKeyword" :placeholder="placeholder" @keydown.enter="saveKeyWord">

        data:function () {
            return {
                searchKeyword:'',
            }
        },


        methods:{
            saveKeyWord:async function () {
                // 在localStorage保存搜索词
                this.keywordList.push(this.searchKeyword);
                localStorage.keywordList = JSON.stringify(this.keywordList);

                // 利用api搜索音乐
                let result =  await searchMusic(this.searchKeyword);
                this.searchSongs = result.data.result.songs;
                console.log(this.searchSongs)
            },

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐