这里写图片描述

src简单的介绍

这里写图片描述

入口文件main.js

import 'babel-polyfill'  //写在第一位
import Vue from 'vue'
import App from './App'
import router from './router'
import fastclick from 'fastclick'
import VueLazyload from 'vue-lazyload'
import store from './store'import 'common/stylus/index.styl'/* eslint-disable no-unused-vars */
// import vConsole from 'vconsole'fastclick.attach(document.body)Vue.use(VueLazyload, {loading: require('common/image/default.png')  //传一个默认参数
})/* eslint-disable no-new */
new Vue({el: '#app',router,store,render: h => h(App)
})

babel-polyfill是es6底层铺垫即支持一些API,比如promise,balbel-runtime为es6语法转义,fastclick解决移动端点击300毫秒的延迟

devDependencies 里面的插件(比如各种loader,babel全家桶及各种webpack的插件等)只用于开发环境,不用于生产环境,因此不需要打包;而 dependencies 是需要发布到生产环境的,是要打包的。

dependencies:应用能够正常运行所依赖的包。这种 dependencies 是最常见的,用户在使用 npm install 安装你的包时会自动安装这些依赖。
devDependencies:开发应用时所依赖的工具包。通常是一些开发、测试、打包工具,例如 webpack、ESLint、Mocha。应用正常运行并不依赖于这些包,用户在使用 npm install 安装你的包时也不会安装这些依赖。

{"name": "vue-music","version": "1.0.0","description": "音乐播放器","author": "songhao","private": true,"scripts": {"dev": "node build/dev-server.js","start": "node build/dev-server.js","build": "node build/build.js","lint": "eslint --ext .js,.vue src"},"dependencies": {"babel-runtime": "^6.0.0","vue": "^2.3.3","vue-router": "^2.5.3","vuex": "^2.3.1","fastclick": "^1.0.6","vue-lazyload": "1.0.3","axios": "^0.16.1","jsonp": "0.2.1","better-scroll": "^0.1.15","create-keyframe-animation": "^0.1.0","js-base64": "^2.1.9","lyric-parser": "^1.0.1","good-storage": "^1.0.1"},"devDependencies": {"autoprefixer": "^6.7.2","babel-core": "^6.22.1","babel-eslint": "^7.1.1","babel-loader": "^6.2.10","babel-plugin-transform-runtime": "^6.22.0","babel-preset-env": "^1.3.2","babel-preset-stage-2": "^6.22.0","babel-register": "^6.22.0","babel-polyfill": "^6.2.0","chalk": "^1.1.3","connect-history-api-fallback": "^1.3.0","copy-webpack-plugin": "^4.0.1","css-loader": "^0.28.0","eslint": "^3.19.0","eslint-friendly-formatter": "^2.0.7","eslint-loader": "^1.7.1","eslint-plugin-html": "^2.0.0","eslint-config-standard": "^6.2.1","eslint-plugin-promise": "^3.4.0","eslint-plugin-standard": "^2.0.1","eventsource-polyfill": "^0.9.6","express": "^4.14.1","extract-text-webpack-plugin": "^2.0.0","file-loader": "^0.11.1","friendly-errors-webpack-plugin": "^1.1.3","html-webpack-plugin": "^2.28.0","http-proxy-middleware": "^0.17.3","webpack-bundle-analyzer": "^2.2.1","semver": "^5.3.0","shelljs": "^0.7.6","opn": "^4.0.2","optimize-css-assets-webpack-plugin": "^1.3.0","ora": "^1.2.0","rimraf": "^2.6.0","url-loader": "^0.5.8","vue-loader": "^11.3.4","vue-style-loader": "^2.0.5","vue-template-compiler": "^2.3.3","webpack": "^2.3.3","webpack-dev-middleware": "^1.10.0","webpack-hot-middleware": "^2.18.0","webpack-merge": "^4.1.0","stylus": "^0.54.5","stylus-loader": "^2.1.1","vconsole": "^2.5.2"},"engines": {"node": ">= 4.0.0","npm": ">= 3.0.0"},"browserslist": ["> 1%","last 2 versions","not ie <= 8"]
}

index.html

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport"content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"><title>vue-music</title></head><body><div id="app"></div><!-- built files will be auto injected --></body>
</html>

APP.vue

<template><div id="app" @touchmove.prevent><m-header></m-header><tab></tab><keep-alive><router-view></router-view></keep-alive>//全局的播放器组件<player></player></div>
</template><script type="text/ecmascript-6">import MHeader from 'components/m-header/m-header'import Player from 'components/player/player'import Tab from 'components/tab/tab'export default {components: {MHeader,Tab,Player}}
</script>

jsonp原理

它发送的不是一个ajax请求,是创建了一个script标签不受同源策略的影响,通过src指向服务器的地址,在地址后面加一个callback=a,服务器解析这个URL发现有一个callback=a的参数,返回数据的时候调用这个a方法,前端定义的a方法就能直接拿到数据

最后返回的时候从1开始截取,是因为上面的方法已经添加了&符号,所有返回&符之后的内容

jsonp的封装 这个js放置于静态文件夹下

import originJsonp from 'jsonp'   //jsonp 结合promise 封装export default function jsonp(url, data, option) {url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)return new Promise((resolve, reject) => {originJsonp(url, option, (err, data) => {if (!err) {resolve(data)} else {reject(err)}})})
}export function param(data) {let url = ''for (var k in data) {let value = data[k] !== undefined ? data[k] : ''url += '&' + k + '=' + encodeURIComponent(value)//新型写法 es6写法//url += `&${k}=${encodeURIComponent(value)}`   es6语法}return url ? url.substring(1) : ''
}

推荐页面 recommend.js 使用jsonp 调取轮播图的数据

用到了es6对象的合并方法Object.assign,浅拷贝的方法

import jsonp from 'common/js/jsonp'
import {commonParams, options} from './config'export function getRecommend() {const url = 'https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg'const data = Object.assign({}, commonParams, {  //assign es6语法platform: 'h5',uin: 0,needNewCode: 1})return jsonp(url, data, options)
}

config.js 因为数据是爬的,所以定义了通用的参数对象,私有的参数通过assign方法添加

export const commonParams = {g_tk: 1928093487,inCharset: 'utf-8',outCharset: 'utf-8',notice: 0,format: 'jsonp'
}export const options = {param: 'jsonpCallback'
}export const ERR_OK = 0

components/recommend.vue 在组件中调用接口

export default {data() {return {recommends: []}},created() {this._getRecommend()},methods: {_getRecommend() {getRecommend().then((res) => {if (res.code === ERR_OK) {this.recommends = res.data.slider}})}},components: {Slider}}
<div v-if="recommends.length" class="slider-wrapper" ref="sliderWrapper"><slider><div v-for="item in recommends"><a :href="item.linkUrl"><img class="needsclick" @load="loadImage" :src="item.picUrl"><!-- 如果fastclick监听到有class为needsclick就不会拦截 --></a></div></slider></div>

这里用到了slider组件以及slot的知识,也遇到了一个坑,因为数据响应 必须确定有数据v-if="recommends.length"才能保证插槽的正确显示

dom.js ,比较重要

操作dom的文件,位于通用静态文件

//是否有指定class存在
export function hasClass(el, className) {let reg = new RegExp('(^|\\s)' + className + '(\\s|$)')return reg.test(el.className)
}
//如果存在什么都不做,否则就设置添加
export function addClass(el, className) {if (hasClass(el, className)) {return}let newClass = el.className.split(' ')newClass.push(className)el.className = newClass.join(' ')
}//展现了方法的设置技巧,一个getter、一个setter
export function getData(el, name, val) {const prefix = 'data-'if (val) {return el.setAttribute(prefix + name, val)}return el.getAttribute(prefix + name)
}
//下面的方法,在歌手详情页的自组件music-list用到,用于控制属性的兼容性
let elementStyle = document.createElement('div').stylelet vendor = (() => {let transformNames = {webkit: 'webkitTransform',Moz: 'MozTransform',O: 'OTransform',ms: 'msTransform',standard: 'transform'}for (let key in transformNames) {if (elementStyle[transformNames[key]] !== undefined) {return key}}return false
})()export function prefixStyle(style) {if (vendor === false) {return false}if (vendor === 'standard') {return style}
//数据的拼接,首字母大写加上剩余的部分return vendor + style.charAt(0).toUpperCase() + style.substr(1)
}

从下面开始开始编写项目

首先是推荐页面,由轮播图和热门歌单组成

轮播图的数据通过jsonp可以得到,但是热门歌单因为有referer、host的认证,所以需要在dev-server.js设置代理,(欺骗服务器)用到axios而不是jsonp

bulid目录下dev-server.js处理代理

require('./check-versions')()var config = require('../config')
if (!process.env.NODE_ENV) {process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
}var opn = require('opn')
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var proxyMiddleware = require('http-proxy-middleware')
var webpackConfig = require('./webpack.dev.conf')
var axios = require('axios') //第一步// default port where dev server listens for incoming traffic
var port = process.env.PORT || config.dev.port
// automatically open browser, if not set will be false
var autoOpenBrowser = !!config.dev.autoOpenBrowser
// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
var proxyTable = config.dev.proxyTablevar app = express()var apiRoutes = express.Router()   //以下是后端代理接口 第二步apiRoutes.get('/getDiscList', function (req, res) {var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'axios.get(url, {headers: {referer: 'https://c.y.qq.com/',host: 'c.y.qq.com'},params: req.query}).then((response) => {res.json(response.data)  //输出到浏览器的res}).catch((e) => {console.log(e)})
})apiRoutes.get('/lyric', function (req, res) {  //这是另一个接口下节将用到var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'axios.get(url, {headers: {referer: 'https://c.y.qq.com/',host: 'c.y.qq.com'},params: req.query}).then((response) => {var ret = response.dataif (typeof ret === 'string') {var reg = /^\w+\(({[^()]+})\)$/var matches = ret.match(reg)if (matches) {ret = JSON.parse(matches[1])}}res.json(ret)}).catch((e) => {console.log(e)})
})app.use('/api', apiRoutes)   //最后一步var compiler = webpack(webpackConfig)var devMiddleware = require('webpack-dev-middleware')(compiler, {publicPath: webpackConfig.output.publicPath,quiet: true
})var hotMiddleware = require('webpack-hot-middleware')(compiler, {log: () => {}
})
// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) {compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {hotMiddleware.publish({ action: 'reload' })cb()})
})// proxy api requests
Object.keys(proxyTable).forEach(function (context) {var options = proxyTable[context]if (typeof options === 'string') {options = { target: options }}app.use(proxyMiddleware(options.filter || context, options))
})// handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')())// serve webpack bundle output
app.use(devMiddleware)// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware)// serve pure static assets
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))var uri = 'http://localhost:' + portvar _resolve
var readyPromise = new Promise(resolve => {_resolve = resolve
})console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {console.log('> Listening at ' + uri + '\n')// when env is testing, don't need open itif (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {opn(uri)}_resolve()
})var server = app.listen(port)module.exports = {ready: readyPromise,close: () => {server.close()}
}

recommend.js 使用axios 调取热门歌单的数据

export function getDiscList() {const url = '/api/getDiscList'const data = Object.assign({}, commonParams, {platform: 'yqq',hostUin: 0,sin: 0,ein: 29,sortId: 5,needNewCode: 0,categoryId: 10000000,rnd: Math.random(),format: 'json'})return axios.get(url, {params: data}).then((res) => {return Promise.resolve(res.data)})
}

slider轮播图组件用到了dom.js中的addclass方法,引入了better-scroll,注意一下window.addEventListener,初始化的时候这个方法this._setSliderWidth(true)传入true,来控制2倍的dom复制,特别注意初始化dots的方法

<template><div class="slider" ref="slider"><div class="slider-group" ref="sliderGroup"><slot></slot></div><div class="dots"><spanclass="dot":class="{active: currentPageIndex === index }"v-for="(item, index) in dots"></span></div></div>
</template><script type="text/ecmascript-6">
import { addClass } from "common/js/dom";
import BScroll from "better-scroll";export default {name: "slider",props: {loop: {type: Boolean,default: true},autoPlay: {type: Boolean,default: true},interval: {type: Number,default: 4000}},data() {return {dots: [],currentPageIndex: 0};},mounted() {setTimeout(() => {this._setSliderWidth();this._initDots();this._initSlider();if (this.autoPlay) {this._play();}}, 20);window.addEventListener("resize", () => {if (!this.slider) {return;}this._setSliderWidth(true);this.slider.refresh();});},//keep-active下的声明周期,相当于小程序的onshowactivated() {if (this.autoPlay) {this._play();}},//组件销毁后清除定时器,有利于内存释放deactivated() {clearTimeout(this.timer);},beforeDestroy() {clearTimeout(this.timer);},methods: {//计算轮播的宽度_setSliderWidth(isResize) {this.children = this.$refs.sliderGroup.children;let width = 0;let sliderWidth = this.$refs.slider.clientWidth;for (let i = 0; i < this.children.length; i++) {let child = this.children[i];addClass(child, "slider-item");child.style.width = sliderWidth + "px";width += sliderWidth;}if (this.loop && !isResize) {width += 2 * sliderWidth;}this.$refs.sliderGroup.style.width = width + "px";},//初始化BScroll_initSlider() {this.slider = new BScroll(this.$refs.slider, {scrollX: true,scrollY: false,momentum: false,snap: true,snapLoop: this.loop,snapThreshold: 0.3,snapSpeed: 400});// 设置currentPageIndexthis.slider.on("scrollEnd", () => {let pageIndex = this.slider.getCurrentPage().pageX;if (this.loop) {pageIndex -= 1;}this.currentPageIndex = pageIndex;if (this.autoPlay) {this._play();}});//手动出发的时候清楚定时器this.slider.on("beforeScrollStart", () => {if (this.autoPlay) {clearTimeout(this.timer);}});},//初始化dots_initDots() {this.dots = new Array(this.children.length);},//轮播关键实现_play() {let pageIndex = this.currentPageIndex + 1;if (this.loop) {pageIndex += 1;}this.timer = setTimeout(() => {this.slider.goToPage(pageIndex, 0, 400);}, this.interval);}}
};
</script><style scoped lang="stylus" rel="stylesheet/stylus">
@import '~common/stylus/variable';.slider {min-height: 1px;.slider-group {position: relative;overflow: hidden;white-space: nowrap;.slider-item {float: left;box-sizing: border-box;overflow: hidden;text-align: center;a {display: block;width: 100%;overflow: hidden;text-decoration: none;}img {display: block;width: 100%;}}}.dots {position: absolute;right: 0;left: 0;bottom: 12px;text-align: center;font-size: 0;.dot {display: inline-block;margin: 0 4px;width: 8px;height: 8px;border-radius: 50%;background: $color-text-l;&.active {width: 20px;border-radius: 5px;background: $color-text-ll;}}}
}
</style>

loading组件

<template><div class="loading"><img width="24" height="24" src="./loading.gif"><p class="desc">{{title}}</p></div>
</template>
<script type="text/ecmascript-6">export default {props: {title: {type: String,default: '正在载入...'}}}
</script>
<style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable".loadingwidth: 100%text-align: center.descline-height: 20pxfont-size: $font-size-smallcolor: $color-text-l
</style>

接下来开发推荐页面滚动列表--仿原声应用的scorllview,所以抽出来一个公用组件Scroll.vue

<template><div ref="wrapper"><slot></slot></div>
</template><script type="text/ecmascript-6">import BScroll from 'better-scroll'export default {props: {probeType: {type: Number,default: 1},click: {type: Boolean,default: true},listenScroll: {type: Boolean,default: false},data: {type: Array,default: null},pullup: {type: Boolean,default: false},beforeScroll: {type: Boolean,default: false},refreshDelay: {type: Number,default: 20}},mounted() {setTimeout(() => {this._initScroll()}, 20)},methods: {_initScroll() {if (!this.$refs.wrapper) {return}this.scroll = new BScroll(this.$refs.wrapper, {probeType: this.probeType,click: this.click})if (this.listenScroll) {let me = thisthis.scroll.on('scroll', (pos) => {me.$emit('scroll', pos)})}if (this.pullup) {this.scroll.on('scrollEnd', () => {if (this.scroll.y <= (this.scroll.maxScrollY + 50)) {this.$emit('scrollToEnd')}})}if (this.beforeScroll) {this.scroll.on('beforeScrollStart', () => {this.$emit('beforeScroll')})}},disable() {this.scroll && this.scroll.disable()},enable() {this.scroll && this.scroll.enable()},refresh() {this.scroll && this.scroll.refresh()},//用于歌手页面scrollTo() {this.scroll && this.scroll.scrollTo.apply(this.scroll, arguments)},//用于歌手页面scrollToElement() {this.scroll && this.scroll.scrollToElement.apply(this.scroll, arguments)}},watch: {data() {setTimeout(() => {this.refresh()}, this.refreshDelay)}}}
</script><style scoped lang="stylus" rel="stylesheet/stylus"></style>

recommend.vue 推荐页面

可能会遇到一个问题,初始化后不能滚动,是因为高度的问题,所以给img加了一个方法,注意h2标签的应用,以及图片懒加载,这里提到了vuex的使用,那怎么给vuex提交数据细心的同学可能会发现↓↓↓↓↓ scroll的用法,只对下面的第一个div起作用

通过图片的高度撑起盒子,通过loadImage的方法限制让方法只执行一次!很实用的方法

<template><div class="recommend" ref="recommend"><scroll ref="scroll" class="recommend-content" :data="discList"><div><div v-if="recommends.length" class="slider-wrapper" ref="sliderWrapper"><slider><div v-for="item in recommends"><a :href="item.linkUrl"><img class="needsclick" @load="loadImage" :src="item.picUrl"></a></div></slider></div><div class="recommend-list"><h1 class="list-title">热门歌单推荐</h1><ul><li @click="selectItem(item)" v-for="item in discList" class="item"><div class="icon"><img width="60" height="60" v-lazy="item.imgurl"></div><div class="text"><h2 class="name" v-html="item.creator.name"></h2><p class="desc" v-html="item.dissname"></p></div></li></ul></div></div><div class="loading-container" v-show="!discList.length"><loading></loading></div></scroll><router-view></router-view></div>
</template><script type="text/ecmascript-6">import Slider from 'base/slider/slider'import Loading from 'base/loading/loading'import Scroll from 'base/scroll/scroll'import {getRecommend, getDiscList} from 'api/recommend'import {playlistMixin} from 'common/js/mixin'import {ERR_OK} from 'api/config'import {mapMutations} from 'vuex'export default {mixins: [playlistMixin],data() {return {recommends: [],discList: []}},created() {this._getRecommend()this._getDiscList()},methods: {handlePlaylist(playlist) {const bottom = playlist.length > 0 ? '60px' : ''this.$refs.recommend.style.bottom = bottomthis.$refs.scroll.refresh()},//通过图片的高度撑起盒子,通过下面的方法限制让方法只执行一次!loadImage() {if (!this.checkloaded) {this.checkloaded = truethis.$refs.scroll.refresh()}},selectItem(item) {this.$router.push({path: `/recommend/${item.dissid}`})this.setDisc(item)},_getRecommend() {getRecommend().then((res) => {if (res.code === ERR_OK) {this.recommends = res.data.slider}})},_getDiscList() {getDiscList().then((res) => {if (res.code === ERR_OK) {this.discList = res.data.list}})},...mapMutations({setDisc: 'SET_DISC'})},components: {Slider,Loading,Scroll}}
</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable".recommendposition: fixedwidth: 100%top: 88pxbottom: 0.recommend-contentheight: 100%overflow: hidden.slider-wrapperposition: relativewidth: 100%overflow: hidden.recommend-list.list-titleheight: 65pxline-height: 65pxtext-align: centerfont-size: $font-size-mediumcolor: $color-theme.itemdisplay: flexbox-sizing: border-boxalign-items: centerpadding: 0 20px 20px 20px.iconflex: 0 0 60pxwidth: 60pxpadding-right: 20px.textdisplay: flexflex-direction: columnjustify-content: centerflex: 1line-height: 20pxoverflow: hiddenfont-size: $font-size-medium.namemargin-bottom: 10pxcolor: $color-text.desccolor: $color-text-d.loading-containerposition: absolutewidth: 100%top: 50%transform: translateY(-50%)
</style>

为什么变量定义在created里面而不是data里面?

因为这些变量不需要被监听,定义在data、props中的变量vue都会添加一个getter、setter方法用来监听数据变化实现双向数据绑定

向上滚动Y值为负数

代码详细注释 listview组件

<template><scroll @scroll="scroll":listen-scroll="listenScroll":probe-type="probeType":data="data"class="listview"ref="listview"><ul><li v-for="group in data" class="list-group" ref="listGroup"><h2 class="list-group-title">{{group.title}}</h2><uL><li @click="selectItem(item)" v-for="item in group.items" class="list-group-item"><img class="avatar" v-lazy="item.avatar"><span class="name">{{item.name}}</span></li></uL></li></ul><div class="list-shortcut" @touchstart.stop.prevent="onShortcutTouchStart" @touchmove.stop.prevent="onShortcutTouchMove"@touchend.stop><ul><li v-for="(item, index) in shortcutList" :data-index="index" class="item":class="{'current':currentIndex===index}">{{item}}</li></ul></div><div class="list-fixed" ref="fixed" v-show="fixedTitle"><div class="fixed-title">{{fixedTitle}} </div></div><div v-show="!data.length" class="loading-container"><loading></loading></div></scroll>
</template><script type="text/ecmascript-6">import Scroll from 'base/scroll/scroll'import Loading from 'base/loading/loading'import {getData} from 'common/js/dom'const TITLE_HEIGHT = 30  //向上顶起的元素高度const ANCHOR_HEIGHT = 18 // 字母导航的高度 (字体高度加上padding值)export default {//接受参数的类型(父组件传入的数据)props: {data: {type: Array,default: []}},//计算属性computed: {//展示字母导航的数据shortcutList() {return this.data.map((group) => {return group.title.substr(0, 1)})},//字母浮层的数据fixedTitle() {if (this.scrollY > 0) {return ''}return this.data[this.currentIndex] ? this.data[this.currentIndex].title : ''}},data() {return {scrollY: -1, //scroll组件传入的y轴currentIndex: 0, //当前联动的下标diff: -1 //控制字母浮层是否被下一块内容顶上去,(是一个顶上去的效果)}}, //为什么要定义在created里面而不是data里面?created() {this.probeType = 3  //scroll组件需要的参数,表示不节流,慢滚动与快滚动都生效this.listenScroll = true //是否触发scroll组件的监听事件this.touch = {} //定义的一个touch事件this.listHeight = [] //获取list的高度,是一个数组},methods: {selectItem(item) {this.$emit('select', item)},onShortcutTouchStart(e) {let anchorIndex = getData(e.target, 'index')let firstTouch = e.touches[0]this.touch.y1 = firstTouch.pageYthis.touch.anchorIndex = anchorIndexthis._scrollTo(anchorIndex)},onShortcutTouchMove(e) {let firstTouch = e.touches[0]this.touch.y2 = firstTouch.pageY//最后 | 0 表示向下取整let delta = (this.touch.y2 - this.touch.y1) / ANCHOR_HEIGHT | 0let anchorIndex = parseInt(this.touch.anchorIndex) + deltathis._scrollTo(anchorIndex)},refresh() {this.$refs.listview.refresh()},//获取scroll组件传入的scroll值scroll(pos) {this.scrollY = pos.y},//计算列表的高度_calculateHeight() {this.listHeight = []const list = this.$refs.listGrouplet height = 0this.listHeight.push(height)for (let i = 0; i < list.length; i++) {let item = list[i]height += item.clientHeightthis.listHeight.push(height)}},_scrollTo(index) {//控制touchstart,点击边缘地带if (!index && index !== 0) {return}//控制touchstart,点击边缘地带if (index < 0) {index = 0} else if (index > this.listHeight.length - 2) { // 控制touchmove,向上滚动的时候,可能大于最后一项的优化index = this.listHeight.length - 2}// 控制touchstart,点击后通过手动设置scrollY实现,点击联动this.scrollY = -this.listHeight[index]//实现列表的滚动this.$refs.listview.scrollToElement(this.$refs.listGroup[index], 0)}},watch: {//监听data,当数据变化,延迟20ms等都dom渲染完毕,再计算data() {setTimeout(() => {this._calculateHeight()}, 20)},//监听scrollY的值 scrollY(newY) {const listHeight = this.listHeight// 当滚动到顶部,newY>0if (newY > 0) {this.currentIndex = 0return}// 在中间部分滚动for (let i = 0; i < listHeight.length - 1; i++) {let height1 = listHeight[i]let height2 = listHeight[i + 1]if (-newY >= height1 && -newY < height2) {this.currentIndex = ithis.diff = height2 + newYreturn}}// 当滚动到底部,且-newY大于最后一个元素的上限this.currentIndex = listHeight.length - 2},//控制字母浮层是否要被顶上去diff(newVal) {let fixedTop = (newVal > 0 && newVal < TITLE_HEIGHT) ? newVal - TITLE_HEIGHT : 0if (this.fixedTop === fixedTop) {return}this.fixedTop = fixedTopthis.$refs.fixed.style.transform = `translate3d(0,${fixedTop}px,0)`}},components: {Scroll,Loading}}</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable".listviewposition: relativewidth: 100%height: 100%overflow: hiddenbackground: $color-background.list-grouppadding-bottom: 30px.list-group-titleheight: 30pxline-height: 30pxpadding-left: 20pxfont-size: $font-size-smallcolor: $color-text-lbackground: $color-highlight-background.list-group-itemdisplay: flexalign-items: centerpadding: 20px 0 0 30px.avatarwidth: 50pxheight: 50pxborder-radius: 50%.namemargin-left: 20pxcolor: $color-text-lfont-size: $font-size-medium.list-shortcutposition: absolutez-index: 30right: 0top: 50%transform: translateY(-50%)width: 20pxpadding: 20px 0border-radius: 10pxtext-align: centerbackground: $color-background-dfont-family: Helvetica.itempadding: 3pxline-height: 1color: $color-text-lfont-size: $font-size-small&.currentcolor: $color-theme.list-fixedposition: absolutetop: 0left: 0width: 100%.fixed-titleheight: 30pxline-height: 30pxpadding-left: 20pxfont-size: $font-size-smallcolor: $color-text-lbackground: $color-highlight-background.loading-containerposition: absolutewidth: 100%top: 50%transform: translateY(-50%)
</style>

Singer class类

export default class Singer {constructor({id, name}) {this.id = idthis.name = namethis.avatar = `https://y.gtimg.cn/music/photo_new/T001R300x300M000${id}.jpg?max_age=2592000`}
}

歌手页面 singer.vue ?‍? 代码注释,字母排序

引入listview组件,有一个20毫秒的定时器,关键在于左右联动的思路很重要,以及关于diff的处理增强用户体验

<template><div class="singer" ref="singer"><list-view @select="selectSinger" :data="singers" ref="list"></list-view><router-view></router-view></div>
</template><script>import ListView from 'base/listview/listview'import {getSingerList} from 'api/singer'import {ERR_OK} from 'api/config'import Singer from 'common/js/singer'import {mapMutations} from 'vuex'  //对Mutations的封装是个语法糖import {playlistMixin} from 'common/js/mixin'const HOT_SINGER_LEN = 10const HOT_NAME = '热门'export default {mixins: [playlistMixin],data() {return {singers: []}},created() {this._getSingerList()},methods: {handlePlaylist(playlist) {const bottom = playlist.length > 0 ? '60px' : ''this.$refs.singer.style.bottom = bottomthis.$refs.list.refresh()}, //跳到歌手详情页面selectSinger(singer) {this.$router.push({path: `/singer/${singer.id}`})//调用被映射出来的方法,把数据传递到vuex里面,到这一步完成setter设置this.setSinger(singer)},_getSingerList() {getSingerList().then((res) => {if (res.code === ERR_OK) {this.singers = this._normalizeSinger(res.data.list)}})},//整理数据结构_normalizeSinger(list) {//首先定义热门数据对象let map = {hot: {title: HOT_NAME,items: []}}list.forEach((item, index) => {//默认前10条为热门数据if (index < HOT_SINGER_LEN) {map.hot.items.push(new Singer({name: item.Fsinger_name,id: item.Fsinger_mid}))}//key 为ABCDEF。。。。。。const key = item.Findexif (!map[key]) {map[key] = {title: key,items: []}}map[key].items.push(new Singer({name: item.Fsinger_name,id: item.Fsinger_mid}))})// 为了得到有序列表,我们需要处理 maplet ret = []let hot = []for (let key in map) {let val = map[key]if (val.title.match(/[a-zA-Z]/)) {ret.push(val)} else if (val.title === HOT_NAME) {hot.push(val)}}//对字母排序ret.sort((a, b) => {return a.title.charCodeAt(0) - b.title.charCodeAt(0)})return hot.concat(ret)},//做一层映射,映射到mutations...mapMutations({setSinger: 'SET_SINGER'})},components: {ListView}}</script>

nextTic延时函数 es6 FindIndex方法

vuex 状态管理

使用场景

  1. 多组件的状态共享
  2. 路由间复杂数据传递

vuex
mutation-type 用来定义常量,便于项目维护,mutation同步修改数据

export const SET_SINGER = 'SET_SINGER'export const SET_PLAYING_STATE = 'SET_PLAYING_STATE'export const SET_FULL_SCREEN = 'SET_FULL_SCREEN'export const SET_PLAYLIST = 'SET_PLAYLIST'export const SET_SEQUENCE_LIST = 'SET_SEQUENCE_LIST'export const SET_PLAY_MODE = 'SET_PLAY_MODE'export const SET_CURRENT_INDEX = 'SET_CURRENT_INDEX'export const SET_DISC = 'SET_DISC'export const SET_TOP_LIST = 'SET_TOP_LIST'export const SET_SEARCH_HISTORY = 'SET_SEARCH_HISTORY'export const SET_PLAY_HISTORY = 'SET_PLAY_HISTORY'export const SET_FAVORITE_LIST = 'SET_FAVORITE_LIST'

mutations,接收两个参数,state就是state.js定义的变量,另一个就是入参(此参数要改变state里的值)

import * as types from './mutation-types'const mutations = {[types.SET_SINGER](state, singer) {state.singer = singer},[types.SET_PLAYING_STATE](state, flag) {state.playing = flag},[types.SET_FULL_SCREEN](state, flag) {state.fullScreen = flag},[types.SET_PLAYLIST](state, list) {state.playlist = list},[types.SET_SEQUENCE_LIST](state, list) {state.sequenceList = list},[types.SET_PLAY_MODE](state, mode) {state.mode = mode},[types.SET_CURRENT_INDEX](state, index) {state.currentIndex = index},[types.SET_DISC](state, disc) {state.disc = disc},[types.SET_TOP_LIST](state, topList) {state.topList = topList},[types.SET_SEARCH_HISTORY](state, history) {state.searchHistory = history},[types.SET_PLAY_HISTORY](state, history) {state.playHistory = history},[types.SET_FAVORITE_LIST](state, list) {state.favoriteList = list}
}
export default mutations

getters,相当于vuex的计算属性

export const singer = state => state.singerexport const playing = state => state.playingexport const fullScreen = state => state.fullScreenexport const playlist = state => state.playlistexport const sequenceList = state => state.sequenceListexport const mode = state => state.modeexport const currentIndex = state => state.currentIndexexport const currentSong = (state) => {return state.playlist[state.currentIndex] || {}
}export const disc = state => state.discexport const topList = state => state.topListexport const searchHistory = state => state.searchHistoryexport const playHistory = state => state.playHistoryexport const favoriteList = state => state.favoriteList

index.js初始化vuex,启用debug

import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
import state from './state'
import mutations from './mutations'
import createLogger from 'vuex/dist/logger' //通过他能在控制台看到每次修改的日志Vue.use(Vuex)const debug = process.env.NODE_ENV !== 'production'  //debug模式,是否是通过state来修改数据,只有在run dev 的模式下可行,应该他对性能也有消耗,不建议在正式环境使用export default new Vuex.Store({actions,getters,state,mutations,strict: debug,plugins: debug ? [createLogger()] : []
})

state.js

import {playMode} from 'common/js/config'
import {loadSearch, loadPlay, loadFavorite} from 'common/js/cache'const state = {singer: {},playing: false, //是否播放fullScreen: false, //是否全屏播放playlist: [], //播放列表sequenceList: [], // 顺序列表mode: playMode.sequence, //播放模式currentIndex: -1, //当前播放的那首歌disc: {},topList: {},searchHistory: loadSearch(),playHistory: loadPlay(),favoriteList: loadFavorite()
}export default state

actions 处理异步操作、对mutations的封装(批量处理mutations)

import * as types from './mutation-types'
import {playMode} from 'common/js/config'
import {shuffle} from 'common/js/util'
import {saveSearch, clearSearch, deleteSearch, savePlay, saveFavorite, deleteFavorite} from 'common/js/cache'
//findindex 用来找出 歌曲在当前列表 下的index
function findIndex(list, song) {return list.findIndex((item) => {return item.id === song.id})
}
//选择播放
export const selectPlay = function ({commit, state}, {list, index}) {commit(types.SET_SEQUENCE_LIST, list) //设置值if (state.mode === playMode.random) {let randomList = shuffle(list)commit(types.SET_PLAYLIST, randomList)index = findIndex(randomList, list[index])} else {commit(types.SET_PLAYLIST, list)}commit(types.SET_CURRENT_INDEX, index) //播放索引commit(types.SET_FULL_SCREEN, true) //播放器打开commit(types.SET_PLAYING_STATE, true) //播放状态打开
}
//music-list里面的随机播放全部 事件
export const randomPlay = function ({commit}, {list}) {commit(types.SET_PLAY_MODE, playMode.random)commit(types.SET_SEQUENCE_LIST, list)let randomList = shuffle(list)commit(types.SET_PLAYLIST, randomList)commit(types.SET_CURRENT_INDEX, 0)commit(types.SET_FULL_SCREEN, true)commit(types.SET_PLAYING_STATE, true)
}export const insertSong = function ({commit, state}, song) {let playlist = state.playlist.slice()let sequenceList = state.sequenceList.slice()let currentIndex = state.currentIndex// 记录当前歌曲let currentSong = playlist[currentIndex]// 查找当前列表中是否有待插入的歌曲并返回其索引let fpIndex = findIndex(playlist, song)// 因为是插入歌曲,所以索引+1currentIndex++// 插入这首歌到当前索引位置playlist.splice(currentIndex, 0, song)// 如果已经包含了这首歌if (fpIndex > -1) {// 如果当前插入的序号大于列表中的序号if (currentIndex > fpIndex) {playlist.splice(fpIndex, 1)currentIndex--} else {playlist.splice(fpIndex + 1, 1)}}let currentSIndex = findIndex(sequenceList, currentSong) + 1let fsIndex = findIndex(sequenceList, song)sequenceList.splice(currentSIndex, 0, song)if (fsIndex > -1) {if (currentSIndex > fsIndex) {sequenceList.splice(fsIndex, 1)} else {sequenceList.splice(fsIndex + 1, 1)}}commit(types.SET_PLAYLIST, playlist)commit(types.SET_SEQUENCE_LIST, sequenceList)commit(types.SET_CURRENT_INDEX, currentIndex)commit(types.SET_FULL_SCREEN, true)commit(types.SET_PLAYING_STATE, true)
}export const saveSearchHistory = function ({commit}, query) {commit(types.SET_SEARCH_HISTORY, saveSearch(query))
}export const deleteSearchHistory = function ({commit}, query) {commit(types.SET_SEARCH_HISTORY, deleteSearch(query))
}export const clearSearchHistory = function ({commit}) {commit(types.SET_SEARCH_HISTORY, clearSearch())
}export const deleteSong = function ({commit, state}, song) {let playlist = state.playlist.slice()let sequenceList = state.sequenceList.slice()let currentIndex = state.currentIndexlet pIndex = findIndex(playlist, song)playlist.splice(pIndex, 1)let sIndex = findIndex(sequenceList, song)sequenceList.splice(sIndex, 1)if (currentIndex > pIndex || currentIndex === playlist.length) {currentIndex--}commit(types.SET_PLAYLIST, playlist)commit(types.SET_SEQUENCE_LIST, sequenceList)commit(types.SET_CURRENT_INDEX, currentIndex)if (!playlist.length) {commit(types.SET_PLAYING_STATE, false)} else {commit(types.SET_PLAYING_STATE, true)}
}export const deleteSongList = function ({commit}) {commit(types.SET_CURRENT_INDEX, -1)commit(types.SET_PLAYLIST, [])commit(types.SET_SEQUENCE_LIST, [])commit(types.SET_PLAYING_STATE, false)
}export const savePlayHistory = function ({commit}, song) {commit(types.SET_PLAY_HISTORY, savePlay(song))
}export const saveFavoriteList = function ({commit}, song) {commit(types.SET_FAVORITE_LIST, saveFavorite(song))
}export const deleteFavoriteList = function ({commit}, song) {commit(types.SET_FAVORITE_LIST, deleteFavorite(song))
}

用vuex在路由间传递复杂数据

歌手页面完成数据的设置,在歌手详情页面开始获取数据
代码注释:获取单个数据字段,刷新的边界处理

歌手详情页,为了组件重用抽出来一个music-list.vue,在此基础又抽出来一个song-list.vue,有两层组件

song类

将乱而散的数据整理成我们想要的数据

import {getLyric} from 'api/song'
import {ERR_OK} from 'api/config'
import {Base64} from 'js-base64'export default class Song {constructor({id, mid, singer, name, album, duration, image, url}) {this.id = idthis.mid = midthis.singer = singerthis.name = namethis.album = albumthis.duration = durationthis.image = imagethis.url = url}getLyric() {if (this.lyric) {return Promise.resolve(this.lyric)}return new Promise((resolve, reject) => {getLyric(this.mid).then((res) => {if (res.retcode === ERR_OK) {this.lyric = Base64.decode(res.lyric)resolve(this.lyric)} else {reject('no lyric')}})})}
}//工厂函数,调用song类
export function createSong(musicData) {return new Song({id: musicData.songid,mid: musicData.songmid,singer: filterSinger(musicData.singer),name: musicData.songname,album: musicData.albumname,duration: musicData.interval,image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`,url: `http://ws.stream.qqmusic.qq.com/${musicData.songid}.m4a?fromtag=46`})
}
//这个方法是将name数组按照/的方式展示,两个以上有效
function filterSinger(singer) {let ret = []if (!singer) {return ''}singer.forEach((s) => {ret.push(s.name)})return ret.join('/')
}

歌手详情页,transition动画、song类的应用

<template><transition name="slide"><music-list :title="title" :bg-image="bgImage" :songs="songs"></music-list></transition>
</template><script type="text/ecmascript-6">import MusicList from 'components/music-list/music-list'import {getSingerDetail} from 'api/singer'import {ERR_OK} from 'api/config'import {createSong} from 'common/js/song'import {mapGetters} from 'vuex'  //通过mapgetters语法糖export default {computed: {//只需要数据结构的某一个字段title() {return this.singer.name},//只需要数据结构的某一个字段bgImage() {return this.singer.avatar},//位于计算属性,获取vuex里面的数据...mapGetters(['singer'])},data() {return {songs: []}},created() {this._getDetail()},methods: {//如果用户在当前页面刷新,返回上一个路由,这是一个边界问题_getDetail() {if (!this.singer.id) {this.$router.push('/singer')return}//请求数据getSingerDetail(this.singer.id).then((res) => {if (res.code === ERR_OK) {this.songs = this._normalizeSongs(res.data.list)}})},_normalizeSongs(list) {let ret = []list.forEach((item) => {let {musicData} = itemif (musicData.songid && musicData.albummid) {ret.push(createSong(musicData))}})return ret}},components: {MusicList}}
</script>//只需要数据结构的某一个字段
<style scoped lang="stylus" rel="stylesheet/stylus">.slide-enter-active, .slide-leave-activetransition: all 0.3s.slide-enter, .slide-leave-totransform: translate3d(100%, 0, 0)x轴  , y轴  ,z轴
</style>

歌手详情,子组件music-list

<template><div class="music-list"><div class="back" @click="back"><i class="icon-back"></i></div><h1 class="title" v-html="title"></h1>//歌手头像背景,关注背景图的设置,以及样式,传说中的10:7写法???????<div class="bg-image" :style="bgStyle" ref="bgImage"><div class="play-wrapper"><div ref="playBtn" v-show="songs.length>0" class="play" @click="random"><i class="icon-play"></i><span class="text">随机播放全部</span></div></div>//用来控制模糊层,但是兼容不好,pc、和部分安卓看不到效果,只有iOS可以看到<div class="filter" ref="filter"></div></div>//用于歌曲列表向上滚动,来做遮挡层<div class="bg-layer" ref="layer"></div><scroll :data="songs" @scroll="scroll":listen-scroll="listenScroll" :probe-type="probeType" class="list" ref="list"><div class="song-list-wrapper"><song-list :songs="songs" :rank="rank" @select="selectItem"></song-list></div><div v-show="!songs.length" class="loading-container"><loading></loading></div></scroll></div>
</template><script type="text/ecmascript-6">import Scroll from 'base/scroll/scroll'import Loading from 'base/loading/loading'import SongList from 'base/song-list/song-list'import {prefixStyle} from 'common/js/dom'import {playlistMixin} from 'common/js/mixin'import {mapActions} from 'vuex'  //语法糖用于获取actionsconst RESERVED_HEIGHT = 40 //重制高度,向上滚动的时候预留的高度//下面是用到的两个属性,拼接浏览器前缀做浏览器兼容const transform = prefixStyle('transform') const backdrop = prefixStyle('backdrop-filter')export default {mixins: [playlistMixin],props: {bgImage: {type: String,default: ''},songs: {type: Array,default: []},title: {type: String,default: ''},rank: {type: Boolean,default: false}},data() {return {scrollY: 0}},computed: {//计算属性设置背景bgStyle() {return `background-image:url(${this.bgImage})`}},created() {this.probeType = 3this.listenScroll = true},mounted() {this.imageHeight = this.$refs.bgImage.clientHeightthis.minTransalteY = -this.imageHeight + RESERVED_HEIGHTthis.$refs.list.$el.style.top = `${this.imageHeight}px`},methods: {handlePlaylist(playlist) {const bottom = playlist.length > 0 ? '60px' : ''this.$refs.list.$el.style.bottom = bottomthis.$refs.list.refresh()},scroll(pos) {this.scrollY = pos.y},back() {this.$router.back()},//当前点击的歌曲selectItem(item, index) {this.selectPlay({list: this.songs,index})},//随机播放全部歌曲random() {this.randomPlay({list: this.songs})},//一般会将这个方法放到methods对象的末尾...mapActions(['selectPlay','randomPlay'])},watch: {scrollY(newVal) {let translateY = Math.max(this.minTransalteY, newVal) //最大不超过this.minTransalteYlet scale = 1let zIndex = 0let blur = 0const percent = Math.abs(newVal / this.imageHeight) //获取绝对值if (newVal > 0) { //向上滚动的时候scale = 1 + percentzIndex = 10} else {blur = Math.min(20, percent * 20) //最小是20}this.$refs.layer.style[transform] = `translate3d(0,${translateY}px,0)`this.$refs.filter.style[backdrop] = `blur(${blur}px)`if (newVal < this.minTransalteY) {  //向上滚动的时候zIndex = 10this.$refs.bgImage.style.paddingTop = 0this.$refs.bgImage.style.height = `${RESERVED_HEIGHT}px`this.$refs.playBtn.style.display = 'none'} else { //向下滚动的时候再恢复默认this.$refs.bgImage.style.paddingTop = '70%'this.$refs.bgImage.style.height = 0this.$refs.playBtn.style.display = ''}this.$refs.bgImage.style[transform] = `scale(${scale})`this.$refs.bgImage.style.zIndex = zIndex}},components: {Scroll,Loading,SongList}}
</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable"@import "~common/stylus/mixin".music-listposition: fixedz-index: 100top: 0left: 0bottom: 0right: 0background: $color-background.backposition absolutetop: 0left: 6pxz-index: 50.icon-backdisplay: blockpadding: 10pxfont-size: $font-size-large-xcolor: $color-theme.titleposition: absolutetop: 0left: 10%z-index: 40width: 80%no-wrap()text-align: centerline-height: 40pxfont-size: $font-size-largecolor: $color-text.bg-imageposition: relativewidth: 100%height: 0padding-top: 70%transform-origin: topbackground-size: cover.play-wrapperposition: absolutebottom: 20pxz-index: 50width: 100%.playbox-sizing: border-boxwidth: 135pxpadding: 7px 0margin: 0 autotext-align: centerborder: 1px solid $color-themecolor: $color-themeborder-radius: 100pxfont-size: 0.icon-playdisplay: inline-blockvertical-align: middlemargin-right: 6pxfont-size: $font-size-medium-x.textdisplay: inline-blockvertical-align: middlefont-size: $font-size-small.filterposition: absolutetop: 0left: 0width: 100%height: 100%background: rgba(7, 17, 27, 0.4).bg-layerposition: relativeheight: 100%background: $color-background.listposition: fixedtop: 0bottom: 0width: 100%background: $color-background.song-list-wrapperpadding: 20px 30px.loading-containerposition: absolutewidth: 100%top: 50%transform: translateY(-50%)
</style>

song-list子组件

<template><div class="song-list"><ul><li @click="selectItem(song, index)" class="item" v-for="(song, index) in songs"><div class="rank" v-show="rank"><span :class="getRankCls(index)" v-text="getRankText(index)"></span></div><div class="content"><h2 class="name">{{song.name}}</h2><p class="desc">{{getDesc(song)}}</p></div></li></ul></div>
</template><script type="text/ecmascript-6">export default {props: {songs: {type: Array,default: []},rank: {type: Boolean,default: false}},methods: {//向父组件传递事件selectItem(item, index) {this.$emit('select', item, index)},getDesc(song) {return `${song.singer}·${song.album}`},getRankCls(index) {if (index <= 2) {return `icon icon${index}`} else {return 'text'}},getRankText(index) {if (index > 2) {return index + 1}}}}
</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable"@import "~common/stylus/mixin".song-list.itemdisplay: flexalign-items: centerbox-sizing: border-boxheight: 64pxfont-size: $font-size-medium.rankflex: 0 0 25pxwidth: 25pxmargin-right: 30pxtext-align: center.icondisplay: inline-blockwidth: 25pxheight: 24pxbackground-size: 25px 24px&.icon0bg-image('first')&.icon1bg-image('second')&.icon2bg-image('third').textcolor: $color-themefont-size: $font-size-large.contentflex: 1line-height: 20pxoverflow: hidden.nameno-wrap()color: $color-text.descno-wrap()margin-top: 4pxcolor: $color-text-d
</style>

随机播放 技术实现 随机数组

//随机数
function getRandomInt(min, max) {return Math.floor(Math.random() * (max - min + 1) + min)
}
//把数组打乱
export function shuffle(arr) {let _arr = arr.slice()for (let i = 0; i < _arr.length; i++) {let j = getRandomInt(0, i)let t = _arr[i]_arr[i] = _arr[j]_arr[j] = t}return _arr
}export function debounce(func, delay) {let timerreturn function (...args) {if (timer) {clearTimeout(timer)}timer = setTimeout(() => {func.apply(this, args)}, delay)}
}

时间戳转分秒 补零方法

 //转换时间format(interval) {interval = interval | 0 //时间戳 向下取整const minute = interval / 60 | 0  //向下取整const second = this._pad(interval % 60)return `${minute}:${second}`},//时间补零 n相当于补充的字符串的长度_pad(num, n = 2) {let len = num.toString().length //获取字符串的长度while (len < n) {num = '0' + numlen++}return num},

播放器内置组件 player.vue,通过actions的方法--selectPlay,在此组件拿到currentSong,这里再重点说一下mutations和它的type要做到命名一致,nutations本质就是函数,第一个参数是state第二个参数是要修改的对象值

条形进度条应用到全屏播放

clientWidth 为content+padding的值

<template><div class="progress-bar" ref="progressBar" @click="progressClick"><div class="bar-inner"><!-- 背景 --><div class="progress" ref="progress"></div><!-- 小圆点 --><div class="progress-btn-wrapper" ref="progressBtn"@touchstart.prevent="progressTouchStart"@touchmove.prevent="progressTouchMove"@touchend="progressTouchEnd"><div class="progress-btn"></div></div></div></div>
</template><script type="text/ecmascript-6">import {prefixStyle} from 'common/js/dom'const progressBtnWidth = 16const transform = prefixStyle('transform')export default {props: {percent: {type: Number,default: 0}},created() {this.touch = {}  //创建一个touch对象},methods: {progressTouchStart(e) {//创建一个标志,意思它已经初始化完this.touch.initiated = true//手指的位置this.touch.startX = e.touches[0].pageX//当前滚动,滚动条的位置this.touch.left = this.$refs.progress.clientWidth},progressTouchMove(e) {//如果初始化完则什么都不做if (!this.touch.initiated) {return}const deltaX = e.touches[0].pageX - this.touch.startX //计算差值 //max 的0  意思不能小于0 、、、、min,不能超过整个滚动条的宽度const offsetWidth = Math.min(this.$refs.progressBar.clientWidth - progressBtnWidth, Math.max(0, this.touch.left + deltaX)) this._offset(offsetWidth)},progressTouchEnd() {this.touch.initiated = false//滚动完后要给父组件派发一个事件this._triggerPercent()},//点击改变歌曲播放进度progressClick(e) {const rect = this.$refs.progressBar.getBoundingClientRect() //是一个获取距离的方法 也就是当前内容距离屏幕的左右间距const offsetWidth = e.pageX - rect.leftthis._offset(offsetWidth)// 这里当我们点击 progressBtn 的时候,e.offsetX 获取不对// this._offset(e.offsetX)this._triggerPercent()},_triggerPercent() {const barWidth = this.$refs.progressBar.clientWidth - progressBtnWidthconst percent = this.$refs.progress.clientWidth / barWidththis.$emit('percentChange', percent)},//偏移方法_offset(offsetWidth) {this.$refs.progress.style.width = `${offsetWidth}px`  //获取进度条的位置,距离左右的距离this.$refs.progressBtn.style[transform] = `translate3d(${offsetWidth}px,0,0)`  //小球的偏移}},watch: {//它是不断改变的percent(newPercent) {//大于0 而且不是在拖动的状态下,拖动的时候不要改变if (newPercent >= 0 && !this.touch.initiated) {const barWidth = this.$refs.progressBar.clientWidth - progressBtnWidth  //进度条的总宽度 内容-按钮的宽度const offsetWidth = newPercent * barWidth //应该偏移的宽度this._offset(offsetWidth)}}}}
</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable".progress-barheight: 30px.bar-innerposition: relativetop: 13pxheight: 4pxbackground: rgba(0, 0, 0, 0.3).progressposition: absoluteheight: 100%background: $color-theme.progress-btn-wrapperposition: absoluteleft: -8pxtop: -13pxwidth: 30pxheight: 30px.progress-btnposition: relativetop: 7pxleft: 7pxbox-sizing: border-boxwidth: 16pxheight: 16pxborder: 3px solid $color-textborder-radius: 50%background: $color-theme
</style>

圆形进度条 用到SVG

<template><div class="progress-circle"><!-- viewBox 视口位置 width、height 是显示到页面的宽高 --><svg :width="radius" :height="radius" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg"><!-- 内层圆圈 r半径 cx\yx为圆心的坐标,说明这个圆是100的宽度 --><circle class="progress-background" r="50" cx="50" cy="50" fill="transparent"/><!-- 外层圆圈 stroke-dasharray描边 stroke-dashoffset偏移量--><circle class="progress-bar" r="50" cx="50" cy="50" fill="transparent" :stroke-dasharray="dashArray":stroke-dashoffset="dashOffset"/></svg><slot></slot></div>
</template><script type="text/ecmascript-6">export default {props: {radius: {type: Number,default: 100},percent: {type: Number,default: 0}},data() {return {dashArray: Math.PI * 100}},computed: {dashOffset() {return (1 - this.percent) * this.dashArray}}}
</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable".progress-circleposition: relativecirclestroke-width: 8pxtransform-origin: center&.progress-backgroundtransform: scale(0.9)stroke: $color-theme-d&.progress-bartransform: scale(0.9) rotate(-90deg)stroke: $color-theme
</style>

播放器内核

<template><div class="player" v-show="playlist.length>0"><!-- 下面用到了动画的js钩子,用它来实现左下到右上的飞跃 --><transition name="normal"@enter="enter" @after-enter="afterEnter" @leave="leave"@after-leave="afterLeave"><!-- 全屏播放器 --><div class="normal-player" v-show="fullScreen"><!-- 背景虚化处理 --><div class="background"><img width="100%" height="100%" :src="currentSong.image"></div><div class="top"><!-- 收起按钮 --><div class="back" @click="back"><i class="icon-back"></i></div><!-- 标题/作者 --><h1 class="title" v-html="currentSong.name"></h1><h2 class="subtitle" v-html="currentSong.singer"></h2></div><div class="middle"@touchstart.prevent="middleTouchStart"@touchmove.prevent="middleTouchMove"@touchend="middleTouchEnd"><!-- 播放器左侧 --><div class="middle-l" ref="middleL"><div class="cd-wrapper" ref="cdWrapper"><!-- 当前播放歌曲的海报 --><div class="cd" :class="cdCls"><img class="image" :src="currentSong.image"></div></div><div class="playing-lyric-wrapper"><div class="playing-lyric">{{playingLyric}}</div></div></div><!-- 播放器右侧 歌词列表 --><scroll class="middle-r" ref="lyricList" :data="currentLyric && currentLyric.lines"><div class="lyric-wrapper"><div v-if="currentLyric"><p ref="lyricLine"class="text":class="{'current': currentLineNum ===index}"v-for="(line,index) in currentLyric.lines">{{line.txt}}</p></div></div></scroll></div><div class="bottom"><div class="dot-wrapper"><span class="dot" :class="{'active':currentShow==='cd'}"></span><span class="dot" :class="{'active':currentShow==='lyric'}"></span></div><!-- 条形进度条的大盒子 --><div class="progress-wrapper"><!-- 歌曲开始播放时间 --><span class="time time-l">{{format(currentTime)}}</span><!-- 条形进度条 --><div class="progress-bar-wrapper"><progress-bar :percent="percent" @percentChange="onProgressBarChange"></progress-bar></div><!-- 歌曲结束时间 --><span class="time time-r">{{format(currentSong.duration)}}</span></div><div class="operators"><!-- 歌曲播放模式 --><div class="icon i-left" @click="changeMode"><i :class="iconMode"></i></div><!-- 上一首 --><div class="icon i-left" :class="disableCls"><i @click="prev" class="icon-prev"></i></div><!-- 播放与暂停 --><div class="icon i-center" :class="disableCls"><i @click="togglePlaying" :class="playIcon"></i></div><!-- 下一首 --><div class="icon i-right" :class="disableCls"><i @click="next" class="icon-next"></i></div><!-- 收藏按钮 --><div class="icon i-right"><i @click="toggleFavorite(currentSong)" class="icon" :class="getFavoriteIcon(currentSong)"></i></div></div></div></div></transition><!-- 收起后的迷你播放器 --><transition name="mini"><div class="mini-player" v-show="!fullScreen" @click="open"><div class="icon"><img :class="cdCls" width="40" height="40" :src="currentSong.image"></div><div class="text"><h2 class="name" v-html="currentSong.name"></h2><p class="desc" v-html="currentSong.singer"></p></div><!-- 圆形进度条 用到svg --><div class="control"><progress-circle :radius="radius" :percent="percent"><i @click.stop="togglePlaying" class="icon-mini" :class="miniIcon"></i></progress-circle></div><div class="control" @click.stop="showPlaylist"><i class="icon-playlist"></i></div></div></transition><playlist ref="playlist"></playlist><!-- 音频播放器 核心 --><audio ref="audio" :src="currentSong.url" @play="ready" @error="error" @timeupdate="updateTime"@ended="end"></audio></div>
</template><script type="text/ecmascript-6">import {mapGetters, mapMutations, mapActions} from 'vuex'import animations from 'create-keyframe-animation' //用到这个动画库import {prefixStyle} from 'common/js/dom'import ProgressBar from 'base/progress-bar/progress-bar'import ProgressCircle from 'base/progress-circle/progress-circle'import {playMode} from 'common/js/config'import Lyric from 'lyric-parser'import Scroll from 'base/scroll/scroll'import {playerMixin} from 'common/js/mixin'import Playlist from 'components/playlist/playlist'//下面的对象是 'common/js/config' 里面的内容
// export const playMode = {
//   sequence: 0, //顺序播放
//   loop: 1, //循环播放
//   random: 2 //随机播放
// }const transform = prefixStyle('transform')const transitionDuration = prefixStyle('transitionDuration')export default {mixins: [playerMixin],data() {return {songReady: false, //控制播放器,歌曲加载完后再走下面的逻辑currentTime: 0, //当前歌曲播放的时间radius: 32,currentLyric: null,currentLineNum: 0,currentShow: 'cd',playingLyric: ''}},computed: {cdCls() {return this.playing ? 'play' : 'play pause'},//字体图标的应用playIcon() {return this.playing ? 'icon-pause' : 'icon-play'},//字体图标的应用miniIcon() {return this.playing ? 'icon-pause-mini' : 'icon-play-mini'},//添加歌曲不能播放的状态样式disableCls() {return this.songReady ? '' : 'disable'},//歌曲播放的比例percent() {return this.currentTime / this.currentSong.duration},...mapGetters(['currentIndex','fullScreen','playing'])},created() {this.touch = {}},methods: {back() {this.setFullScreen(false)},open() {this.setFullScreen(true)},// el 是元素、done执行会跳到afterEnterenter(el, done) {const {x, y, scale} = this._getPosAndScale()//从零先跳到那个初始化的位置,60的时候放大,100的时候恢复正常let animation = {0: {transform: `translate3d(${x}px,${y}px,0) scale(${scale})`},60: {transform: `translate3d(0,0,0) scale(1.1)`},100: {transform: `translate3d(0,0,0) scale(1)`}}animations.registerAnimation({name: 'move',animation,presets: {duration: 400,easing: 'linear'}})// 把动画追加到制定元素animations.runAnimation(this.$refs.cdWrapper, 'move', done)},afterEnter() {animations.unregisterAnimation('move')this.$refs.cdWrapper.style.animation = ''},// el 是元素、done执行会跳到afterLeaaveleave(el, done) {this.$refs.cdWrapper.style.transition = 'all 0.4s'const {x, y, scale} = this._getPosAndScale()this.$refs.cdWrapper.style[transform] = `translate3d(${x}px,${y}px,0) scale(${scale})`this.$refs.cdWrapper.addEventListener('transitionend', done)},afterLeave() {this.$refs.cdWrapper.style.transition = ''this.$refs.cdWrapper.style[transform] = ''},// 切换歌曲播放与暂停togglePlaying() {if (!this.songReady) {return}this.setPlayingState(!this.playing)if (this.currentLyric) {this.currentLyric.togglePlay()}},//歌曲播放结束事件end() {//如果是单曲循环,播放结束后再次播放if (this.mode === playMode.loop) {this.loop()} else {this.next()}},loop() {this.$refs.audio.currentTime = 0this.$refs.audio.play()this.setPlayingState(true)if (this.currentLyric) {this.currentLyric.seek(0)}},// 切换下一首歌曲next() {//歌曲没有加载完if (!this.songReady) {return}if (this.playlist.length === 1) {this.loop()return} else {let index = this.currentIndex + 1 //下一首歌,所以要加一//如果到底类,就重置为0if (index === this.playlist.length) {index = 0}//设置vuex的indexthis.setCurrentIndex(index)//如果是暂停状态下,切换,就调取方法改变它的值 if (!this.playing) {this.togglePlaying()}}this.songReady = false},prev() {//歌曲没有加载完if (!this.songReady) {return}if (this.playlist.length === 1) {this.loop()return} else {let index = this.currentIndex - 1//如果到头,就换成最后一首歌if (index === -1) {index = this.playlist.length - 1}this.setCurrentIndex(index)//如果是暂停状态下,切换,就调取方法改变它的值 if (!this.playing) {this.togglePlaying()}}this.songReady = false},//歌曲加载完事件ready() {this.songReady = truethis.savePlayHistory(this.currentSong)},error() {this.songReady = true},//获取歌曲当前播放的时间长度updateTime(e) {this.currentTime = e.target.currentTime},//转换时间format(interval) {interval = interval | 0 //时间戳 向下取整const minute = interval / 60 | 0  //向下取整const second = this._pad(interval % 60)return `${minute}:${second}`},//监听子组件返回的数值,改变播放器的进度onProgressBarChange(percent) {const currentTime = this.currentSong.duration * percentthis.$refs.audio.currentTime = currentTime//如果当前状态没有播放,就去播放歌曲if (!this.playing) {this.togglePlaying()}if (this.currentLyric) {this.currentLyric.seek(currentTime * 1000)}},getLyric() {this.currentSong.getLyric().then((lyric) => {if (this.currentSong.lyric !== lyric) {return}this.currentLyric = new Lyric(lyric, this.handleLyric)if (this.playing) {this.currentLyric.play()}}).catch(() => {this.currentLyric = nullthis.playingLyric = ''this.currentLineNum = 0})},handleLyric({lineNum, txt}) {this.currentLineNum = lineNumif (lineNum > 5) {let lineEl = this.$refs.lyricLine[lineNum - 5]this.$refs.lyricList.scrollToElement(lineEl, 1000)} else {this.$refs.lyricList.scrollTo(0, 0, 1000)}this.playingLyric = txt},showPlaylist() {this.$refs.playlist.show()},middleTouchStart(e) {this.touch.initiated = true// 用来判断是否是一次移动this.touch.moved = falseconst touch = e.touches[0]this.touch.startX = touch.pageXthis.touch.startY = touch.pageY},middleTouchMove(e) {if (!this.touch.initiated) {return}const touch = e.touches[0]const deltaX = touch.pageX - this.touch.startXconst deltaY = touch.pageY - this.touch.startYif (Math.abs(deltaY) > Math.abs(deltaX)) {return}if (!this.touch.moved) {this.touch.moved = true}const left = this.currentShow === 'cd' ? 0 : -window.innerWidthconst offsetWidth = Math.min(0, Math.max(-window.innerWidth, left + deltaX))this.touch.percent = Math.abs(offsetWidth / window.innerWidth)this.$refs.lyricList.$el.style[transform] = `translate3d(${offsetWidth}px,0,0)`this.$refs.lyricList.$el.style[transitionDuration] = 0this.$refs.middleL.style.opacity = 1 - this.touch.percentthis.$refs.middleL.style[transitionDuration] = 0},middleTouchEnd() {if (!this.touch.moved) {return}let offsetWidthlet opacityif (this.currentShow === 'cd') {if (this.touch.percent > 0.1) {offsetWidth = -window.innerWidthopacity = 0this.currentShow = 'lyric'} else {offsetWidth = 0opacity = 1}} else {if (this.touch.percent < 0.9) {offsetWidth = 0this.currentShow = 'cd'opacity = 1} else {offsetWidth = -window.innerWidthopacity = 0}}const time = 300this.$refs.lyricList.$el.style[transform] = `translate3d(${offsetWidth}px,0,0)`this.$refs.lyricList.$el.style[transitionDuration] = `${time}ms`this.$refs.middleL.style.opacity = opacitythis.$refs.middleL.style[transitionDuration] = `${time}ms`this.touch.initiated = false},//时间补零 n相当于补充的字符串的长度_pad(num, n = 2) {let len = num.toString().length //获取字符串的长度while (len < n) {num = '0' + numlen++}return num},_getPosAndScale() {const targetWidth = 40 //目标宽度,小圆圈的宽度const paddingLeft = 40 //目标宽度,小圆圈的左边距const paddingBottom = 30 //目标宽度,小圆圈的下边距const paddingTop = 80 //大唱片到页面顶部的距离const width = window.innerWidth * 0.8 //大唱片的宽度,因为设置的是80%const scale = targetWidth / width //初开始的缩放const x = -(window.innerWidth / 2 - paddingLeft) //初始的x轴,从左下到右上所以是负值const y = window.innerHeight - paddingTop - width / 2 - paddingBottom //初始化 y轴  2分支1的宽度return {x,y,scale}},...mapMutations({setFullScreen: 'SET_FULL_SCREEN'}),...mapActions(['savePlayHistory'])},watch: {currentSong(newSong, oldSong) {if (!newSong.id) {return}//发现ID没变 就什么都不做,在切换模式的时候用到if (newSong.id === oldSong.id) {return}if (this.currentLyric) {this.currentLyric.stop()this.currentTime = 0this.playingLyric = ''this.currentLineNum = 0}// 函数防抖的处理clearTimeout(this.timer)this.timer = setTimeout(() => {this.$refs.audio.play()this.getLyric()}, 1000)},//控制暂停和播放playing(newPlaying) {//先缓存一下引用const audio = this.$refs.audiothis.$nextTick(() => {newPlaying ? audio.play() : audio.pause()})},fullScreen(newVal) {if (newVal) {setTimeout(() => {this.$refs.lyricList.refresh()}, 20)}}},components: {ProgressBar,ProgressCircle,Scroll,Playlist}}
</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~common/stylus/variable"@import "~common/stylus/mixin".player.normal-playerposition: fixedleft: 0right: 0top: 0bottom: 0z-index: 150background: $color-background.backgroundposition: absoluteleft: 0top: 0width: 100%height: 100%z-index: -1opacity: 0.6filter: blur(20px).topposition: relativemargin-bottom: 25px.backposition absolutetop: 0left: 6pxz-index: 50.icon-backdisplay: blockpadding: 9pxfont-size: $font-size-large-xcolor: $color-themetransform: rotate(-90deg).titlewidth: 70%margin: 0 autoline-height: 40pxtext-align: centerno-wrap()font-size: $font-size-largecolor: $color-text.subtitleline-height: 20pxtext-align: centerfont-size: $font-size-mediumcolor: $color-text.middleposition: fixedwidth: 100%top: 80pxbottom: 170pxwhite-space: nowrapfont-size: 0.middle-ldisplay: inline-blockvertical-align: topposition: relativewidth: 100%height: 0padding-top: 80%.cd-wrapperposition: absoluteleft: 10%top: 0width: 80%height: 100%.cdwidth: 100%height: 100%box-sizing: border-boxborder: 10px solid rgba(255, 255, 255, 0.1)border-radius: 50%&.playanimation: rotate 20s linear infinite&.pauseanimation-play-state: paused.imageposition: absoluteleft: 0top: 0width: 100%height: 100%border-radius: 50%.playing-lyric-wrapperwidth: 80%margin: 30px auto 0 autooverflow: hiddentext-align: center.playing-lyricheight: 20pxline-height: 20pxfont-size: $font-size-mediumcolor: $color-text-l.middle-rdisplay: inline-blockvertical-align: topwidth: 100%height: 100%overflow: hidden.lyric-wrapperwidth: 80%margin: 0 autooverflow: hiddentext-align: center.textline-height: 32pxcolor: $color-text-lfont-size: $font-size-medium&.currentcolor: $color-text.bottomposition: absolutebottom: 50pxwidth: 100%.dot-wrappertext-align: centerfont-size: 0.dotdisplay: inline-blockvertical-align: middlemargin: 0 4pxwidth: 8pxheight: 8pxborder-radius: 50%background: $color-text-l&.activewidth: 20pxborder-radius: 5pxbackground: $color-text-ll.progress-wrapperdisplay: flexalign-items: centerwidth: 80%margin: 0px autopadding: 10px 0.timecolor: $color-textfont-size: $font-size-smallflex: 0 0 30pxline-height: 30pxwidth: 30px&.time-ltext-align: left&.time-rtext-align: right.progress-bar-wrapperflex: 1.operatorsdisplay: flexalign-items: center.iconflex: 1color: $color-theme&.disablecolor: $color-theme-difont-size: 30px.i-lefttext-align: right.i-centerpadding: 0 20pxtext-align: centerifont-size: 40px.i-righttext-align: left.icon-favoritecolor: $color-sub-theme&.normal-enter-active, &.normal-leave-activetransition: all 0.4s.top, .bottomtransition: all 0.4s cubic-bezier(0.86, 0.18, 0.82, 1.32)&.normal-enter, &.normal-leave-toopacity: 0.toptransform: translate3d(0, -100px, 0).bottomtransform: translate3d(0, 100px, 0).mini-playerdisplay: flexalign-items: centerposition: fixedleft: 0bottom: 0z-index: 180width: 100%height: 60pxbackground: $color-highlight-background&.mini-enter-active, &.mini-leave-activetransition: all 0.4s&.mini-enter, &.mini-leave-toopacity: 0.iconflex: 0 0 40pxwidth: 40pxpadding: 0 10px 0 20pximgborder-radius: 50%&.playanimation: rotate 10s linear infinite&.pauseanimation-play-state: paused.textdisplay: flexflex-direction: columnjustify-content: centerflex: 1line-height: 20pxoverflow: hidden.namemargin-bottom: 2pxno-wrap()font-size: $font-size-mediumcolor: $color-text.descno-wrap()font-size: $font-size-smallcolor: $color-text-d.controlflex: 0 0 30pxwidth: 30pxpadding: 0 10px.icon-play-mini, .icon-pause-mini, .icon-playlistfont-size: 30pxcolor: $color-theme-d.icon-minifont-size: 32pxposition: absoluteleft: 0top: 0@keyframes rotate0%transform: rotate(0)100%transform: rotate(360deg)
</style>

一级页面向二级页面传参数

首先在路由中定义一个二级,path就是id,再回到推荐页面加一个routerview以及点击事件,到此完成第一步。见下面的部分代码

{path: '/recommend',component: Recommend,children: [{path: ':id',component: Disc}]},
<div class="recommend-list"><h1 class="list-title">热门歌单推荐</h1><ul><li @click="selectItem(item)" v-for="item in discList" class="item"><div class="icon"><img width="60" height="60" v-lazy="item.imgurl"></div><div class="text"><h2 class="name" v-html="item.creator.name"></h2><p class="desc" v-html="item.dissname"></p></div></li></ul></div></div><div class="loading-container" v-show="!discList.length"><loading></loading></div></scroll><router-view></router-view></div>
</template>
selectItem(item) {this.$router.push({path: `/recommend/${item.dissid}`})this.setDisc(item)},

正则整理数据结构

看下面的数据,其实请求接口的时候设置了json但是还是返回了,jsonp的格式怎么办?

if (typeof ret === 'string') {
//以字母开始 +表示一位或多位 \( \) 转义小括号 ()用它来分组 {} 表示下面的{}符号 \(\)表示不是小括号的任意字符 +表示一个或者多个var reg = /^\w+\(({[^\(\)]+})\)$/var matches = response.data.match(reg)if (matches) {ret = JSON.parse(matches[1])}}

在这里插入图片描述

打包后如何运行dist目录

1、npm run build 是本地打包 2、新建prod.server.js 最后运行 node prod.server.js 就能把项目跑起来

var express = require('express')
var config = require('./config/index')
var axios = require('axios')var port = process.env.PORT || config.build.portvar app = express()var apiRoutes = express.Router()apiRoutes.get('/getDiscList', function (req, res) {var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'axios.get(url, {headers: {referer: 'https://c.y.qq.com/',host: 'c.y.qq.com'},params: req.query}).then((response) => {res.json(response.data)}).catch((e) => {console.log(e)})
})apiRoutes.get('/lyric', function (req, res) {var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'axios.get(url, {headers: {referer: 'https://c.y.qq.com/',host: 'c.y.qq.com'},params: req.query}).then((response) => {var ret = response.dataif (typeof ret === 'string') {var reg = /^\w+\(({[^\(\)]+})\)$/var matches = response.data.match(reg)if (matches) {ret = JSON.parse(matches[1])}}res.json(ret)}).catch((e) => {console.log(e)})
})app.use('/api', apiRoutes)app.use(express.static('./dist'))module.exports = app.listen(port, function (err) {if (err) {console.log(err)return}console.log('Listening at http://localhost:' + port + '\n')
})

是为了在build里面加port 让项目跑在这个端口

config/index.js

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {build: {env: require('./prod.env'),port: 9000,index: path.resolve(__dirname, '../dist/index.html'),assetsRoot: path.resolve(__dirname, '../dist'),assetsSubDirectory: 'static',assetsPublicPath: '',productionSourceMap: true,// Gzip off by default as many popular static hosts such as// Surge or Netlify already gzip all static assets for you.// Before setting to `true`, make sure to:// npm install --save-dev compression-webpack-pluginproductionGzip: false,productionGzipExtensions: ['js', 'css'],// Run the build command with an extra argument to// View the bundle analyzer report after build finishes:// `npm run build --report`// Set to `true` or `false` to always turn it on or offbundleAnalyzerReport: process.env.npm_config_report},dev: {env: require('./dev.env'),port: 8080,autoOpenBrowser: true,assetsSubDirectory: 'static',assetsPublicPath: '/',proxyTable: {},// CSS Sourcemaps off by default because relative paths are "buggy"// with this option, according to the CSS-Loader README// (https://github.com/webpack/css-loader#sourcemaps)// In our experience, they generally work as expected,// just be aware of this issue when enabling this option.cssSourceMap: false}
}

如何优化首屏加载 提到了路由懒加载

让组件等于一个方法,这个方法再resolve这个组件

import Vue from 'vue'
import Router from 'vue-router'Vue.use(Router)const Recommend = (resolve) => {import('components/recommend/recommend').then((module) => {resolve(module)})
}const Singer = (resolve) => {import('components/singer/singer').then((module) => {resolve(module)})
}const Rank = (resolve) => {import('components/rank/rank').then((module) => {resolve(module)})
}const Search = (resolve) => {import('components/search/search').then((module) => {resolve(module)})
}const SingerDetail = (resolve) => {import('components/singer-detail/singer-detail').then((module) => {resolve(module)})
}const Disc = (resolve) => {import('components/disc/disc').then((module) => {resolve(module)})
}const TopList = (resolve) => {import('components/top-list/top-list').then((module) => {resolve(module)})
}const UserCenter = (resolve) => {import('components/user-center/user-center').then((module) => {resolve(module)})
}

vue升级的注意事项

在devDependencies里面的vue-template-compiler一定要和vue的版本保持一致否则编译的时候会报错。

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. React+mobx入门教程

    名字完全是为了SEO优化... 谈不上是教程,就说说我的理解,按照我的理解,也许你能入门快点。 我刚接触React的时候,第一个问题是我为什么要用他,这是我的习惯。 从很多角度上来讲我觉得React理念不错,但是并没有什么卵用,当然,学来装逼还是不错的。 首先从实现的角度讲,…...

    2024/4/27 14:50:32
  2. 记腾讯云短信服务PHP SDK接入

    笔者最近做web实验遇到了登录采用短信验证方式,所以需要调用腾讯云的短信接口。腾讯云的短信api提供很多种语言接入,包括python,PHP,node.js,c#等等。我这次用的是PHP SDK。选择腾讯云的短信服务是因为可以申请一个免费的短信服务,可以发送一百条短信(足够我们开发使用了…...

    2024/4/24 13:22:57
  3. 掘金最污的 React16.x 图文视频教程(2万5千字长文-慎入)

    这是一门免费课程,写文章和录制视频这个我花了1个半月时间,如果你觉的不错可以给一个赞。文章和视频中会详细讲解React的基础知识,React版本是16x,也是目前最新版本(我课程录制开始的日期是2019年5月4日)。今年的目标是录制100集前端免费视频教程,可能大部分都会在React框…...

    2024/4/24 13:22:57
  4. java架构师项目实战,高并发集群分布式,大数据高可用视频教程

    —————————————————————————————————————————————————–java架构师项目实战,高并发集群分布式,大数据高可用视频教程,共760G下载地址:https://item.taobao.com/item.htm?id=55588852620101.高级架构师四十二个阶段高 02.J…...

    2024/4/27 15:56:02
  5. 微信小程序视频教程

    微信小程序视频教程,微信小程序项目实战,微信小程序基础入门教程本文出自 “php ecshop 二次开发” 博客,请务必保留此出处http://phpecshop.blog.51cto.com/6296699/1862940NideShop微信小程序商城(Node.js):https://github.com/tumobi/nideshop-mini-program微信小程序全…...

    2024/4/24 13:22:54
  6. 前端、后端,数据结构,编程语言,微信小程序,英语,理综,PS,MySql,Python,JS,Jquery,Ajax,免费百度云资源链接

    高中英语知识点汇总百度云:链接:HTTPS://pan.baidu.com/s/1X0ELSe7LorfLAzNMrUpkxA密码:byo5英语基础语法百度云:链接:HTTPS://pan.baidu.com/s/1Kke8J7a9zLpNtwo0GME4_g密码:S893雅思英语资料百度云:链接:HTTPS://pan.baidu.com/s/182ChB0CvcMmW8NmwD8XF0w密码:md…...

    2024/4/27 14:37:29
  7. 微信小程序实战(仿小米商城)

    小编推荐:Fundebug专注于JavaScript、微信小程序、微信小游戏,Node.js和Java实时BUG监控。真的是一个很好用的bug监控费服务,众多大佬公司都在使用。前言小程序发布以来,凭借无需安装、用完即走、触手可及、无需注册、无需登录、以及社交裂变等多个优势,一路高歌,变得愈来…...

    2024/4/24 13:22:52
  8. (转)一个基于vue2的天气js应用

    基于vue.js 2.0的百度天气应用 vue-weather 基于vue.js 2.0的百度天气应用。 说明 初学vue,在看完一个简单的视频教程和走两遍完官方文档之后仍然感觉云里雾里,知其然不知其所以然(虽然现在好了点)。请教了高手之后人家都说学习新东西的最好方法不就是学到了之后就要用么。…...

    2024/4/24 13:22:51
  9. 2019最新前端妙味课堂全套Vip教程

    课程目录: 秒味课堂VIP全套视频 Angularjs 秒味课堂VIP全套视频 git与github 秒味课堂VIP全套视频 Node.js 妙味课堂VIP全套视频 Bootstrap框架 妙味课堂VIP全套视频 React框架 妙味课堂VIP全套视频 前端初窥篇 妙味课堂VIP全套视频 小试牛刀篇 妙味课堂VIP全套视频 渐入佳境篇…...

    2024/4/24 13:22:54
  10. 微信小程序:nodejs+百度语音合成开发实践

    写在前面,今天突然又整理了这个教程是因为百度的语音合成文本最多可以有1024个字节,而腾讯的只有150个字节。而且开发语言可以自由选择。其中包括nodeJs开发。今天就拿这个做实践。1、在百度AI开放平台注册账号,并申请应用。申请完可以在应用管理看到如下应用,appid,apike…...

    2024/4/27 13:54:05
  11. 史上最全的开发语言大全视频教程

    诚意出售以下视频,有意向请联系QQ,付款百度云发货;JavaScriptjQueryPHP系统/运维JavaReactAPPPythonVue.jsAngularJS大数据人工智能微信数据库Node.js前端开发UI设计区块链 很多时候只要我们找对资源,愿意花时间去学习,25K+绝不是吹的,卖家也是程序员,这些资源都是n年的…...

    2024/4/27 15:27:14
  12. 极客WEB大前端专家级开发工程师培训视频教程

    极客WEB大前端专家级开发工程师培训视频教程 1.走进前端工程师的世界HTML51.HTML5与HTML4的区别2.HTML5新增的主体结构元素3.HTML5新增的的非主体结构元素 4.HTML5表单新增元素与属性5.HTML5表单新增元素与属性(续)6.HTML5改良的input元素的种类 7.HTML5增强的页面元素8.HTML…...

    2024/4/27 15:21:04
  13. python,django,vue.js 免费视频课程学习 推荐

    python 学习视频 1.https://gitbook.cn/gitchat/column/5a7d1a13a7f22b3dffca7e49 2.http://study.163.com/course/introduction.htm?courseId=1003267005#/courseDetail?tab=1 3. http://study.163.com/course/introduction.htm?from=study&share=1&shareId=114328…...

    2024/4/19 21:09:46
  14. 你不知道的Vue.js(相关开源项目库集合)

    内容UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 UI组件element ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 - 基于Vue和WeUI的组件库 iview ★6634 - 基于 Vuejs 的开源 UI 组件库 mint-ui ★6253 - Vue 2的移动UI元素 muse-ui ★3705 …...

    2024/4/19 6:38:48
  15. 视频教程-19年全新React教程全家桶实战redux+antd+dva+Hooks前端js视频-ReactJS

    19年全新React教程全家桶实战redux+antd+dva+Hooks前端js视频7年的开发架构经验,曾就职于国内一线互联网公司,开发工程师,现在是某创业公司技术负责人, 擅长语言有node/java/python,专注于服务端研发,人工智能相关领域, 熟悉分布式高可用系统的架构,大数据处理,微信开放…...

    2024/4/20 7:29:18
  16. Vue 2.0 高级实战-开发移动端音乐WebApp

    前言Vue.js 是最火的前端框架,几乎没有之一,资深程序员这样评价它:“Vue.js 兼具 Angular.js 和 React.js 的优点,并剔除它们的缺点”,很多前端工程师都视Vue.js为心中最理想的框架项目主要技术栈vue2.0 vuex node 已实现功能[x] 图片懒加载 [x] 历史搜索 [x] 音乐收…...

    2024/4/17 0:20:49
  17. Hexo Next 7.71

    准备环境 1.安装Node.js 2.安装Git 3.注册码云 4.安装Hexo 安装命令 npm install hexo-cli -g安装成功界面:搭建本地个人博客 初始化hexo 新建一个空白文件夹(下文提到的“项目根目录”是指你新建的文件夹的位置)用于存放 hexo 资源。在空白文件夹里面打开 Git Bash ,输入下…...

    2024/4/17 20:04:12
  18. React.js 开发参见问题

    文章中我整理了 React.js 开发过程中一些参见问题的解答汇总,供大家参考。1. 一些课程资源课程完整的思维导图请查考文章:React.js 入门与实战课程思维导图,我使用的思维导图软件是 Mac 下的 iThoughtsx。课程网站源码包请参考慕课问答区:求源代码地址,此源码包含了 node_…...

    2024/4/24 13:22:49
  19. Vue技术栈开发实战百度网盘下载

    课程简介:Vue作为前端框架的佼佼者,已经受到广大开发者的青睐,因为Vue的简单易用,使得更多后端开发者,或者非开发人员都能上手一二 本课程通过对100多位开发者调查反馈,用心整理了课程大纲,确保每一节课都会在清晰讲解主要主干知识的同时,穿插Vue基础和ES6/7/8等知识,…...

    2024/4/24 13:22:49
  20. 资源|最新WEB前端开发全套视频教程

    特别说明:资料来源于网络,版权归原作者所有,仅限用于学习交流之用,请勿做它用。如有不妥请联系小睿删除!引言最近很多同学在群里问小睿有么有前端的课程呢?答案是必须的!以下资料是我昨晚冒死在网上冲浪,看到网友收藏的一套完整的web前端开发全套教程,特地将资料分享给…...

    2024/4/24 13:22:47

最新文章

  1. C语言考试程序题会用到的模板

    // 质数判定 int isPrime(int x) {if(x < 2)return 0;for(int i 2;i < x / i;i)if(x % i 0)return 0;return 1; }// 最大公约数 int gcd(int a,int b) {return b 0 ? a : gcd(b,a%b); }// 最小公倍数 int lcm(int a,int b) {return a / gcd(a,b) * b; }// 分解因数 v…...

    2024/4/27 16:43:44
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. Android Framework学习笔记(2)----系统启动

    Android系统的启动流程 启动过程中&#xff0c;用户可控部分是framework的init流程。init是系统中的第一个进程&#xff0c;其它进程都是它的子进程。 启动逻辑源码参照&#xff1a;system/core/init/main.cpp 关键调用顺序&#xff1a;main->FirstStageMain->SetupSel…...

    2024/4/26 21:26:41
  4. 【Godot4自学手册】第三十五节摇杆控制开门

    本节主要实现&#xff0c;在地宫墙壁上安装一扇门&#xff0c;在核实安装一个开门的摇杆&#xff0c;攻击摇杆&#xff0c;打开这扇门&#xff0c;但是只能攻击一次&#xff0c;效果如下&#xff1a; 一、添加完善节点 切换到underground场景&#xff0c;先将TileMap修改一下…...

    2024/4/26 19:55:01
  5. 【外汇早评】美通胀数据走低,美元调整

    原标题:【外汇早评】美通胀数据走低,美元调整昨日美国方面公布了新一期的核心PCE物价指数数据,同比增长1.6%,低于前值和预期值的1.7%,距离美联储的通胀目标2%继续走低,通胀压力较低,且此前美国一季度GDP初值中的消费部分下滑明显,因此市场对美联储后续更可能降息的政策…...

    2024/4/26 18:09:39
  6. 【原油贵金属周评】原油多头拥挤,价格调整

    原标题:【原油贵金属周评】原油多头拥挤,价格调整本周国际劳动节,我们喜迎四天假期,但是整个金融市场确实流动性充沛,大事频发,各个商品波动剧烈。美国方面,在本周四凌晨公布5月份的利率决议和新闻发布会,维持联邦基金利率在2.25%-2.50%不变,符合市场预期。同时美联储…...

    2024/4/26 20:12:18
  7. 【外汇周评】靓丽非农不及疲软通胀影响

    原标题:【外汇周评】靓丽非农不及疲软通胀影响在刚结束的周五,美国方面公布了新一期的非农就业数据,大幅好于前值和预期,新增就业重新回到20万以上。具体数据: 美国4月非农就业人口变动 26.3万人,预期 19万人,前值 19.6万人。 美国4月失业率 3.6%,预期 3.8%,前值 3…...

    2024/4/26 23:05:52
  8. 【原油贵金属早评】库存继续增加,油价收跌

    原标题:【原油贵金属早评】库存继续增加,油价收跌周三清晨公布美国当周API原油库存数据,上周原油库存增加281万桶至4.692亿桶,增幅超过预期的74.4万桶。且有消息人士称,沙特阿美据悉将于6月向亚洲炼油厂额外出售更多原油,印度炼油商预计将每日获得至多20万桶的额外原油供…...

    2024/4/27 4:00:35
  9. 【外汇早评】日本央行会议纪要不改日元强势

    原标题:【外汇早评】日本央行会议纪要不改日元强势近两日日元大幅走强与近期市场风险情绪上升,避险资金回流日元有关,也与前一段时间的美日贸易谈判给日本缓冲期,日本方面对汇率问题也避免继续贬值有关。虽然今日早间日本央行公布的利率会议纪要仍然是支持宽松政策,但这符…...

    2024/4/25 18:39:22
  10. 【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响

    原标题:【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响近日伊朗局势升温,导致市场担忧影响原油供给,油价试图反弹。此时OPEC表态稳定市场。据消息人士透露,沙特6月石油出口料将低于700万桶/日,沙特已经收到石油消费国提出的6月份扩大出口的“适度要求”,沙特将满…...

    2024/4/27 14:22:49
  11. 【外汇早评】美欲与伊朗重谈协议

    原标题:【外汇早评】美欲与伊朗重谈协议美国对伊朗的制裁遭到伊朗的抗议,昨日伊朗方面提出将部分退出伊核协议。而此行为又遭到欧洲方面对伊朗的谴责和警告,伊朗外长昨日回应称,欧洲国家履行它们的义务,伊核协议就能保证存续。据传闻伊朗的导弹已经对准了以色列和美国的航…...

    2024/4/26 21:56:58
  12. 【原油贵金属早评】波动率飙升,市场情绪动荡

    原标题:【原油贵金属早评】波动率飙升,市场情绪动荡因中美贸易谈判不安情绪影响,金融市场各资产品种出现明显的波动。随着美国与中方开启第十一轮谈判之际,美国按照既定计划向中国2000亿商品征收25%的关税,市场情绪有所平复,已经开始接受这一事实。虽然波动率-恐慌指数VI…...

    2024/4/27 9:01:45
  13. 【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试

    原标题:【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试美国和伊朗的局势继续升温,市场风险情绪上升,避险黄金有向上突破阻力的迹象。原油方面稍显平稳,近期美国和OPEC加大供给及市场需求回落的影响,伊朗局势并未推升油价走强。近期中美贸易谈判摩擦再度升级,美国对中…...

    2024/4/26 16:00:35
  14. 【原油贵金属早评】市场情绪继续恶化,黄金上破

    原标题:【原油贵金属早评】市场情绪继续恶化,黄金上破周初中国针对于美国加征关税的进行的反制措施引发市场情绪的大幅波动,人民币汇率出现大幅的贬值动能,金融市场受到非常明显的冲击。尤其是波动率起来之后,对于股市的表现尤其不安。隔夜美国股市出现明显的下行走势,这…...

    2024/4/25 18:39:16
  15. 【外汇早评】美伊僵持,风险情绪继续升温

    原标题:【外汇早评】美伊僵持,风险情绪继续升温昨日沙特两艘油轮再次发生爆炸事件,导致波斯湾局势进一步恶化,市场担忧美伊可能会出现摩擦生火,避险品种获得支撑,黄金和日元大幅走强。美指受中美贸易问题影响而在低位震荡。继5月12日,四艘商船在阿联酋领海附近的阿曼湾、…...

    2024/4/25 18:39:16
  16. 【原油贵金属早评】贸易冲突导致需求低迷,油价弱势

    原标题:【原油贵金属早评】贸易冲突导致需求低迷,油价弱势近日虽然伊朗局势升温,中东地区几起油船被袭击事件影响,但油价并未走高,而是出于调整结构中。由于市场预期局势失控的可能性较低,而中美贸易问题导致的全球经济衰退风险更大,需求会持续低迷,因此油价调整压力较…...

    2024/4/26 19:03:37
  17. 氧生福地 玩美北湖(上)——为时光守候两千年

    原标题:氧生福地 玩美北湖(上)——为时光守候两千年一次说走就走的旅行,只有一张高铁票的距离~ 所以,湖南郴州,我来了~ 从广州南站出发,一个半小时就到达郴州西站了。在动车上,同时改票的南风兄和我居然被分到了一个车厢,所以一路非常愉快地聊了过来。 挺好,最起…...

    2024/4/26 22:01:59
  18. 氧生福地 玩美北湖(中)——永春梯田里的美与鲜

    原标题:氧生福地 玩美北湖(中)——永春梯田里的美与鲜一觉醒来,因为大家太爱“美”照,在柳毅山庄去寻找龙女而错过了早餐时间。近十点,向导坏坏还是带着饥肠辘辘的我们去吃郴州最富有盛名的“鱼头粉”。说这是“十二分推荐”,到郴州必吃的美食之一。 哇塞!那个味美香甜…...

    2024/4/25 18:39:14
  19. 氧生福地 玩美北湖(下)——奔跑吧骚年!

    原标题:氧生福地 玩美北湖(下)——奔跑吧骚年!让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 啊……啊……啊 两…...

    2024/4/26 23:04:58
  20. 扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!

    原标题:扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!扒开伪装医用面膜,翻六倍价格宰客!当行业里的某一品项火爆了,就会有很多商家蹭热度,装逼忽悠,最近火爆朋友圈的医用面膜,被沾上了污点,到底怎么回事呢? “比普通面膜安全、效果好!痘痘、痘印、敏感肌都能用…...

    2024/4/25 2:10:52
  21. 「发现」铁皮石斛仙草之神奇功效用于医用面膜

    原标题:「发现」铁皮石斛仙草之神奇功效用于医用面膜丽彦妆铁皮石斛医用面膜|石斛多糖无菌修护补水贴19大优势: 1、铁皮石斛:自唐宋以来,一直被列为皇室贡品,铁皮石斛生于海拔1600米的悬崖峭壁之上,繁殖力差,产量极低,所以古代仅供皇室、贵族享用 2、铁皮石斛自古民间…...

    2024/4/25 18:39:00
  22. 丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者

    原标题:丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者【公司简介】 广州华彬企业隶属香港华彬集团有限公司,专注美业21年,其旗下品牌: 「圣茵美」私密荷尔蒙抗衰,产后修复 「圣仪轩」私密荷尔蒙抗衰,产后修复 「花茵莳」私密荷尔蒙抗衰,产后修复 「丽彦妆」专注医学护…...

    2024/4/26 19:46:12
  23. 广州械字号面膜生产厂家OEM/ODM4项须知!

    原标题:广州械字号面膜生产厂家OEM/ODM4项须知!广州械字号面膜生产厂家OEM/ODM流程及注意事项解读: 械字号医用面膜,其实在我国并没有严格的定义,通常我们说的医美面膜指的应该是一种「医用敷料」,也就是说,医用面膜其实算作「医疗器械」的一种,又称「医用冷敷贴」。 …...

    2024/4/27 11:43:08
  24. 械字号医用眼膜缓解用眼过度到底有无作用?

    原标题:械字号医用眼膜缓解用眼过度到底有无作用?医用眼膜/械字号眼膜/医用冷敷眼贴 凝胶层为亲水高分子材料,含70%以上的水分。体表皮肤温度传导到本产品的凝胶层,热量被凝胶内水分子吸收,通过水分的蒸发带走大量的热量,可迅速地降低体表皮肤局部温度,减轻局部皮肤的灼…...

    2024/4/27 8:32:30
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57