关于《从零开始撸一个 Vue 组件库》这个项目的一些笔记

b站视频链接:从零开始撸一个 Vue 组件库,搬砖效率提升404倍!_哔哩哔哩_bilibili

在做这个项目的时候遇到了一点问题,通过自己上网查阅资料并解决,以下是一些个人经验笔记。

1、在跑的时候报错,解决error ‘XXX‘ is not defined no-undef且项目没有eslintrc.js文件问题

这是因为eslint的语法校验导致的问题,文件是通过public的index.html中<script src="xxxxxx.js"></script>引入的,没有定义全局变量,项目没有eslintrc.js文件,但是可以在package.json中配置eslint规则

在package.json文件中找到eslintConfig,并配置rules,新增

"vue/multi-word-component-names": "off"

并重新npm i,即可跑通项目。

图示:

2、在跑的时候又突然报错了

需要更改其配置:

代码为:

"@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-eslint": "^10.1.0",
    "clean-webpack-plugin": "^3.0.0",
    "css-loader": "^6.8.1",
    "del": "^6.0.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "gulp": "^4.0.2",
    "gulp-minify-css": "^1.2.4",
    "gulp-sass": "^4.1.0",
    "node-sass": "^5.0.0",
    "sass-loader": "^5.0.0",
    "style-loader": "^3.3.3",
    "vue-loader": "^15.9.6",
    "vue-template-compiler": "^2.6.11",
    "vuepress": "^1.8.2",
    "webpack-cli": "^4.5.0"

并把原来的依赖和package-lock.json这两个东西删掉:

再重新安装依赖

无法npm i时,尝试更换镜像

//查看当前镜像
npm get registry 

//设置淘宝镜像
npm config set registry http://registry.npm.taobao.org

//如果你换成淘宝镜像的话,会影响你发布模块,这时候需要换回npm官网的镜像
 
npm config set registry https://registry.npmjs.org

镜像源是npm的发布不了,换成淘宝的可以发布,但是在packages没看到

需要更换名字,npm上传同名不行

这里就换了自定义的命名上传了,

3、后续npm i -D vuepress时候无法下载,再切换镜像源试一下就能解决了

后续npm i -D vuepress时候无法下载,再切换镜像源试一下

最后在github新建站点,并上传

GitHub仓库地址: GitHub - Wiser714/moocUI: 慕课网组件库

个人站点地址:Wiser714.github.io | 个人站点仓库

 NPM官网下载的地址: mooc-ui-wiser - npm

 源码可自取

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是从零开始封装一个基于videojs和Vue的动态source的视频播放器组件的步骤: 1. 安装video.js和vue-video-player 使用npm安装video.js和vue-video-player: ``` npm install video.js vue-video-player --save ``` 2. 创建Vue组件 在src/components目录下创建一个VideoPlayer.vue的文件,该文件包含以下内容: ```html <template> <div> <video ref="videoPlayer" class="video-js vjs-default-skin vjs-big-play-centered"></video> </div> </template> <script> import videojs from 'video.js'; import 'video.js/dist/video-js.css'; import 'vue-video-player/src/custom-theme.css'; import 'vue-video-player/src/font/font.css'; import 'vue-video-player/src/assets/video-player.css'; export default { name: 'VideoPlayer', props: { sources: { type: Array, required: true }, options: { type: Object, default: () => ({}) } }, mounted() { this.initPlayer(); }, beforeDestroy() { if (this.player) { this.player.dispose(); } }, methods: { initPlayer() { const video = this.$refs.videoPlayer; const playerOptions = Object.assign({ controlBar: { children: { playToggle: {}, progressControl: {}, remainingTimeDisplay: {}, fullscreenToggle: {} } }, sources: this.sources }, this.options); this.player = videojs(video, playerOptions, function onPlayerReady() { console.log('Player ready'); }); } } }; </script> ``` 3. 在Vue项目中使用该组件 在需要使用视频播放器的Vue组件中引入VideoPlayer组件,并传入sources和options参数: ```html <template> <div class="app"> <VideoPlayer :sources="sources" :options="options"></VideoPlayer> </div> </template> <script> import VideoPlayer from '@/components/VideoPlayer.vue'; export default { name: 'App', components: { VideoPlayer }, data() { return { sources: [ { src: 'http://example.com/path/to/video.mp4', type: 'video/mp4' } ], options: { autoplay: false, controls: true, preload: 'auto', fluid: true } }; } }; </script> ``` 这样就完成了从零开始封装一个基于videojs和Vue的动态source的视频播放器组件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值