新建一个vue文件

image.png

image.png

image.png
后面都选第一项 然后y 回车

一、rem实现适配

1.安装rem

  1. yarn add lib-flexible postcss-pxtorem

2.postcss.config.js

  1. module.exports = {
  2. plugins: {
  3. "postcss-pxtorem": {
  4. "rootValue": 75,
  5. "propList": ["*"]
  6. }
  7. }
  8. }

3.新建utils文件夹 config.js文件导入

  1. import Vue from 'vue'
  2. import 'lib-flexible/flexible.js'
  3. import '@/assets/css/reset.css'
  4. export default Vue

4.rem是为移动端而生的要在pc和pad上跑动,一定要在App.vue文件中加

  1. <template>
  2. <div id="app">
  3. <router-view></router-view>
  4. </div>
  5. </template>
  6. <style>
  7. #app{
  8. width:10rem;
  9. margin-left:auto;
  10. margin-right:auto;
  11. }
  12. </style>

5.样式重置

在assets文件夹中新建css文件夹reset.css文件 输入

  1. /* http://meyerweb.com/eric/tools/css/reset/
  2. v2.0 | 20110126
  3. License: none (public domain)
  4. */
  5. html, body, div, span, applet, object, iframe,
  6. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  7. a, abbr, acronym, address, big, cite, code,
  8. del, dfn, em, img, ins, kbd, q, s, samp,
  9. small, strike, strong, sub, sup, tt, var,
  10. b, u, i, center,
  11. dl, dt, dd, ol, ul, li,
  12. fieldset, form, label, legend,
  13. table, caption, tbody, tfoot, thead, tr, th, td,
  14. article, aside, canvas, details, embed,
  15. figure, figcaption, footer, header, hgroup,
  16. menu, nav, output, ruby, section, summary,
  17. time, mark, audio, video {
  18. margin: 0;
  19. padding: 0;
  20. border: 0;
  21. font-size: 100%;
  22. font: inherit;
  23. vertical-align: baseline;
  24. }
  25. /* HTML5 display-role reset for older browsers */
  26. article, aside, details, figcaption, figure,
  27. footer, header, hgroup, menu, nav, section {
  28. display: block;
  29. }
  30. body {
  31. line-height: 1;
  32. }
  33. ol, ul {
  34. list-style: none;
  35. }
  36. blockquote, q {
  37. quotes: none;
  38. }
  39. blockquote:before, blockquote:after,
  40. q:before, q:after {
  41. content: '';
  42. content: none;
  43. }
  44. table {
  45. border-collapse: collapse;
  46. border-spacing: 0;
  47. }

然后再 新建main.js文件中导入

  1. import '@/assets/css/reset.css'

二、配置路由

2-1 配置路由

再routers文件夹下的Index.js文件中输入
安装 yarn add vue-router

  1. import Vue from 'vue';
  2. import Router from 'vue-router'; // 导入router
  3. import Music from '@/views/Music.vue'
  4. import Mv from '@/views/Mv.vue'
  5. Vue.use(Router);
  6. export default new Router({
  7. mode:"history",
  8. routes:[
  9. {
  10. path:'/music',
  11. name:"music",
  12. component:Music
  13. },
  14. {
  15. path:'/mv',
  16. name:"mv",
  17. component:Mv
  18. }
  19. ]
  20. })

2-2 使用路由 App.vue

  1. <template>
  2. <div id="app">
  3. <router-view></router-view>
  4. </div>
  5. </template>

2-3 main.js

  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import router from './routers'
  4. import './utils/config.js'
  5. Vue.config.productionTip = false
  6. new Vue({
  7. router,
  8. render: h => h(App),
  9. }).$mount('#app')

2-4 router-link

  1. <template>
  2. <div id="app">
  3. <div id="nav">
  4. <router-link to="/music">音乐</router-link>
  5. <router-link to="/mv">MV</router-link>
  6. </div>
  7. <router-view></router-view>
  8. </div>
  9. </template>

三、全局过滤器

写在utils config.js文件中

  1. Vue.filter("format",function(val){
  2. if(val.length>6){
  3. val = val.slice(0,6)+"..."
  4. }
  5. return val
  6. })

四、全局组件

utils config.js

  1. import BsBtn from '@/components/BsBtn.vue';
  2. Vue.component('BsBtn',BsBtn)

五、http请求

安装axios
yarn add axios
utils config.js中导入axios

  1. import Vue from 'vue'
  2. import 'lib-flexible/flexible.js'
  3. import '@/assets/css/reset.css'
  4. import axios from 'axios' //
  5. Vue.filter("format",function(val){
  6. if(val.length>8){
  7. val = val.slice(0,8)+"..."
  8. }
  9. return val;
  10. })
  11. axios.defaults.baseURL = 'http://192.168.14.49:5000'; //
  12. Vue.prototype.axios = axios //
  13. export default Vue
  1. mounted(){
  2. this.axios.get("/top/playlist").then(res=>{
  3. this.playlists = res.data.playlists;
  4. })
  5. }