Skip to content

Commit

Permalink
feat(vue3): Migrate to vue 3 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutch12 authored and mercs600 committed Oct 28, 2020
1 parent eaedf0a commit 1e1a90c
Show file tree
Hide file tree
Showing 7 changed files with 4,374 additions and 2,939 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = {
'standard',
'plugin:vue/recommended'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
rules: {
}
}
13 changes: 9 additions & 4 deletions example/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<template>
<div>
<button @click.prevent="changeOptions">Change options</button>
<button @click.prevent="watcher = !watcher">Toggle watch on scrollbar</button>
<button @click.prevent="changeOptions">
Change options
</button>
<button @click.prevent="watcher = !watcher">
Toggle watch on scrollbar
</button>
<scroll
ref="scroll"
:options="options"
Expand All @@ -22,7 +26,8 @@
</template>

<script>
export default {
import { defineComponent } from 'vue'
export default defineComponent({
data () {
return {
content: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum',
Expand All @@ -37,7 +42,7 @@ export default {
this.options.minScrollbarLength = this.options.minScrollbarLength + 50
}
}
}
})
</script>
<style>
.container {
Expand Down
15 changes: 8 additions & 7 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Vue from 'vue'
import { createApp, h } from 'vue'
import App from './App.vue'
import Vue2PerfectScrollbar from '../src'
import '../src/style.css'

Vue.use(Vue2PerfectScrollbar, {
name: 'scroll'
const app = createApp({
render: () => h(App)
})
/* eslint-disable no-new */
new Vue({
el: '#app',
render: h => h(App)

app.use(Vue2PerfectScrollbar, {
name: 'scroll'
})

app.mount('#app')
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@vue/test-utils": "^1.0.0-beta.25",
"@vue/compiler-sfc": "^3.0.2",
"@vue/test-utils": "^2.0.0-beta.7",
"babel-loader": "^8.0.2",
"chai": "^4.1.2",
"css-loader": "^1.0.0",
"eslint": "^5.5.0",
"eslint": "^7.12.0",
"eslint-config-standard": "^12.0.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.0.0-beta.3",
"eslint-plugin-vue": "^7.1.0",
"eslint-webpack-plugin": "^2.1.0",
"karma": "^3.0.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand All @@ -54,20 +55,19 @@
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^3.0.5",
"mocha": "^5.2.0",
"node-sass": "^4.9.3",
"node-sass": "^4.14.1",
"rollup": "^0.65.2",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-uglify": "^5.0.2",
"sass-loader": "^7.1.0",
"sass-loader": "^10.0.4",
"style-loader": "^0.23.0",
"ts-loader": "^5.1.0",
"typescript": "^3.0.3",
"vue": "^2.5.17",
"vue-loader": "^15.4.1",
"ts-loader": "^8.0.7",
"typescript": "^4.0.3",
"vue": "^3.0.2",
"vue-loader": "^16.0.0-beta.8",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.5.17",
"webpack": "^4.17.2",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.7"
Expand Down
30 changes: 25 additions & 5 deletions src/Scrollbar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { h } from 'vue'
import PerfectScrollbar from 'perfect-scrollbar'

const eventNames = [
'scroll',
'ps-scroll-y',
'ps-scroll-x',
'ps-scroll-up',
'ps-scroll-down',
'ps-scroll-left',
'ps-scroll-right',
'ps-y-reach-start',
'ps-y-reach-end',
'ps-x-reach-start',
'ps-x-reach-end'
]

export default {
name: 'PerfectScrollbar',
props: {
Expand All @@ -18,6 +34,7 @@ export default {
default: false
}
},
emits: eventNames,
data () {
return {
ps: null
Expand All @@ -44,13 +61,17 @@ export default {
this.update()
})
},
beforeDestroy () {
beforeUnmount () {
this.destroy()
},
methods: {
create () {
if (!(this.ps && this.$isServer)) {
this.ps = new PerfectScrollbar(this.$refs.container, this.options)

eventNames.forEach(eventName => {
this.ps.element.addEventListener(eventName, event => this.$emit(eventName, event))
})
}
},
createWatcher () {
Expand All @@ -73,13 +94,12 @@ export default {
}
}
},
render (h) {
render () {
return h(this.tag,
{
ref: 'container',
class: 'ps',
on: this.$listeners
class: 'ps'
},
this.$slots.default)
this.$slots.default())
}
}
25 changes: 14 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const ESLintPlugin = require('eslint-webpack-plugin')

if (process.env.NODE_ENV === 'test') {
// exclude NPM deps from test bundle
Expand All @@ -17,16 +18,6 @@ module.exports = {
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|vue)$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'example')
],
exclude: /node_modules/,
loader: 'eslint-loader'
},
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader']
Expand All @@ -52,5 +43,17 @@ module.exports = {
compress: true,
port: 9000
},
plugins: [new VueLoaderPlugin()]
plugins: [
new VueLoaderPlugin(),
new ESLintPlugin({
files: [
'./src',
'./example'
],
extensions: [
'js',
'vue'
]
})
]
}
Loading

0 comments on commit 1e1a90c

Please sign in to comment.