Skip to content

Commit

Permalink
feat: add vue-3 supports
Browse files Browse the repository at this point in the history
  • Loading branch information
avil13 committed Oct 22, 2020
1 parent 1a785bb commit 6cde439
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v3.0.8](https://github.com/avil13/vue-sweetalert2/compare/v3.0.6...v3.0.8)

> 29 August 2020
- fix(packages): removed unused packages [`7181a00`](https://github.com/avil13/vue-sweetalert2/commit/7181a00fd5c02cbe42203f406475389627d672b9)
- feat: update versions [`7ab4f55`](https://github.com/avil13/vue-sweetalert2/commit/7ab4f552f0ef5c760b900be2c19bded8016d5229)
- fix: updated types fix#105 [`dda8d74`](https://github.com/avil13/vue-sweetalert2/commit/dda8d74d8af44dbde83c80eb881e8961aeaab480)

#### [v3.0.6](https://github.com/avil13/vue-sweetalert2/compare/v3.0.5...v3.0.6)

> 29 June 2020
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Vue.js wrapper for SweetAlert2. With support SSR.

## Attention:

When using "Vue3: Composition API" it is better not to use this wrapper.
When using "Vue3: Composition API" it is better **not to use** this wrapper.
It is more practical to call sweetalert2 directly.

Also, it is better to do it to get feedback faster, and be closer to the documentation.
Expand Down Expand Up @@ -46,6 +46,8 @@ npm install -S vue-sweetalert2
}
```

## vue 2

```js
// main.js
import Vue from 'vue';
Expand All @@ -57,6 +59,24 @@ import 'sweetalert2/dist/sweetalert2.min.css';
Vue.use(VueSweetalert2);
```

## vue 3

```js
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'

import VueSweetalert2 from 'vue-sweetalert2';
import 'sweetalert2/dist/sweetalert2.min.css';

const app = createApp(App)

app.use(VueSweetalert2);

app.mount('#app');
```

Now in the global object, you can access all the methods of [sweetalert2](https://github.com/limonte/sweetalert2).

```html
Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ class VueSweetalert2 {
}
}

vue['swal'] = swalFunction;

// add the instance method
if (!Object.prototype.hasOwnProperty.call(vue, '$swal')) {
if (vue.config?.globalProperties && !vue.config.globalProperties.$swal) {
// vue 3
vue.config.globalProperties.$swal = swalFunction;
vue.provide('$swal', swalFunction);
} else if (!Object.prototype.hasOwnProperty.call(vue, '$swal')) {
// vue 2

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
vue.prototype.$swal = swalFunction;
vue['swal'] = swalFunction;
}
}
}
Expand Down

0 comments on commit 6cde439

Please sign in to comment.