時(shí)間:2023-04-23 21:45:02 | 來源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-04-23 21:45:02 來源:網(wǎng)站運(yùn)營(yíng)
【個(gè)人練習(xí)】網(wǎng)易云音樂PC端仿站 Vue 2(一):vue create netease-music
2.配置vue.config.js
文件const { defineConfig } = require('@vue/cli-service')module.exports = defineConfig({ transpileDependencies: true, devServer: { open: true, // 運(yùn)行項(xiàng)目時(shí)自動(dòng)打開頁(yè)面 host: 'localhost', // 設(shè)置打開地址為localhost:8080 }})
3. 運(yùn)行項(xiàng)目npm run serve
4. 網(wǎng)易云音樂API安裝及運(yùn)行git clone git@github.com:Binaryify/NeteaseCloudMusicApi.gitcd NeteaseCloudMusicApinpm install
運(yùn)行:node app.js
出現(xiàn) server running @ http://localhost:3000
即可。路徑 | 組件(功能) | 嵌套級(jí)別 |
---|---|---|
/home | 發(fā)現(xiàn)音樂(首頁(yè)) | 1級(jí) |
/home/discover | 首頁(yè)-推薦 | 2級(jí) |
/home/toplist/:id | 首頁(yè)-排行榜 | 2級(jí) |
/home/playlist | 首頁(yè)-歌單 | 2級(jí) |
/home/djradio | 首頁(yè)-主播電臺(tái) | 2級(jí) |
/home/artist | 首頁(yè)-歌手 | 2級(jí) |
/home/album | 首頁(yè)-新碟上架 | 2級(jí) |
/my | 我的音樂 | 1級(jí) |
/my/artist | 我的音樂-我的歌手 | 2級(jí) |
/my/mv | 我的音樂-我的視頻 | 2級(jí) |
/my/radio | 我的音樂-我的電臺(tái) | 2級(jí) |
/my/playlist/:id | 我的音樂-創(chuàng)建/收藏的歌單 | 2級(jí) |
/friend | 關(guān)注 | 1級(jí) |
/album/:id | 專輯頁(yè)面 | 1級(jí) |
/playlist/:id | 歌單頁(yè)面 | 1級(jí) |
/artist/:id | 歌手頁(yè)面 | 1級(jí) |
/artist/song | 歌手-熱門作品 | 2級(jí) |
/artist/album | 歌手-所有專輯 | 2級(jí) |
/artist/mv | 歌手-相關(guān)MV | 2級(jí) |
/artist/desc | 歌手-藝人介紹 | 2級(jí) |
/song/:id | 歌曲頁(yè)面 | 1級(jí) |
scrollBehavior
,使得路由切換時(shí),頁(yè)面滾動(dòng)條返回頂部。import Vue from 'vue'import VueRouter from 'vue-router'Vue.use(VueRouter)// 路由配置const routes = [ { path: '/', redirect: '/home/discover' }, // "發(fā)現(xiàn)音樂"頁(yè)面(首頁(yè)) { path: '/home', component: () => import('@/views/Home'), children: [ { path: 'discover', component: () => import('@/views/Home/Discover') }, { path: 'toplist/:id?', component: () => import('@/views/Home/TopList') }, { path: 'playlist', component: () => import('@/views/Home/PlayList') }, { path: 'djradio', component: () => import('@/views/Home/DjRadio') }, { path: 'artist', component: () => import('@/views/Home/Artist') }, { path: 'album', component: () => import('@/views/Home/Album') }, ] }, // "我的音樂"頁(yè)面 { path: '/my', component: () => import('@/views/My'), redirect: '/my/playlist', children: [ { path: 'artist', component: () => import('@/views/My/Logged/Artist') }, { path: 'mv', component: () => import('@/views/My/Logged/Mv') }, { path: 'radio', component: () => import('@/views/My/Logged/DjRadio') }, { path: 'playlist/:id?', component: () => import('@/views/My/Logged/PlayList') }, ] }, // "關(guān)注"頁(yè)面 { path: '/friend', component: () => import('@/views/Friend') }, // 專輯頁(yè)面 { path: '/album/:id?', component: () => import('@/views/Album')}, // 歌單頁(yè)面 { path: '/playlist/:id?', component: () => import('@/views/PlayList')}, // 歌手頁(yè)面 { path: '/artist', component: () => import('@/views/Artist'), redirect: '/artist/song', children: [ { path: 'song', component: () => import('@/views/Artist/MainLeft/Song.vue') }, { path: 'album', component: () => import('@/views/Artist/MainLeft/Album.vue') }, { path: 'mv', component: () => import('@/views/Artist/MainLeft/Mv.vue') }, { path: 'desc', component: () => import('@/views/Artist/MainLeft/Desc.vue') }, ] }, // 歌曲頁(yè)面 { path: '/song/:id?', component: () => import('@/views/Song') },]const router = new VueRouter({ routes, // 切換路由時(shí),將滾動(dòng)條復(fù)位到最頂部和最左側(cè) scrollBehavior(to, from, savedPosition) { // savedPosition當(dāng)且僅當(dāng)通過瀏覽器的前進(jìn)/后退按鈕觸發(fā)時(shí)才可用 if (savedPosition) { return savedPosition } else { return { x: 0, y: 0 } } }})export default router
axios
封裝請(qǐng)求工具,調(diào)用接口時(shí)使用。axios
實(shí)例axios
實(shí)例發(fā)送請(qǐng)求,返回Promise
import axios from 'axios'const instance = axios.create({ baseURL: 'http://localhost:3000', timeout: 5000,})// 請(qǐng)求攔截器instance.interceptors.request.use((config) => { let cookie = localStorage.getItem('COOKIE') if (config.method.toLowerCase() === 'get') { if (!config.params) config.params = {} config.params.timerstamp = Date.parse(new Date()) if (cookie && cookie !== '' && !config.params.cookie) { config.params.cookie = cookie } } else { if (!config.data) config.data = {} config.data.timerstamp = Date.parse(new Date()) if (cookie && cookie !== '' && !config.data.cookie) { config.data.cookie = cookie } } return config;}, (error) => { return Promise.reject(error);})// 響應(yīng)攔截器instance.interceptors.response.use((response) => { return response.data;}, (error) => { return Promise.reject(error);})export default (url, method, submitData) => { return instance({ url, method, [method.toLowerCase() === 'get' ? 'params' : 'data']: submitData })}
關(guān)鍵詞:音樂,練習(xí)
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。