https://github.com/tinymins/vue-wechat.js
Wechat sdk for Vue.js.
https://github.com/tinymins/vue-wechat.js
Last synced: 10 months ago
JSON representation
Wechat sdk for Vue.js.
- Host: GitHub
- URL: https://github.com/tinymins/vue-wechat.js
- Owner: tinymins
- Created: 2018-12-03T01:40:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-22T12:44:28.000Z (over 5 years ago)
- Last Synced: 2025-03-30T06:32:04.165Z (10 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/vue-wechat
- Size: 33.2 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vue-wechat
Wechat sdk for Vue.js.
## install
> npm i vue-wechat -s
Import vue-wechat before create `Vue` instance:
```js
import Wechat from 'vue-wechat';
Vue.use(Wechat);
// ...
new Vue({
render: h => h(App),
}).$mount('#app');
```
Import specific version of wechat sdk:
```js
import Wechat from 'vue-wechat/1.2.0';
Vue.use(Wechat);
// ...
new Vue({
render: h => h(App),
}).$mount('#app');
```
Import original wechat sdk object:
```js
import { wechat } from 'vue-wechat';
// import { wx } from 'vue-wechat';
// import { wechat } from 'vue-wechat/1.2.0';
wechat.previewImage({ urls: [''], current: '' });
```
## usage
Global use.
```js
import Vue from 'vue';
Vue.wechat.config({
debug: info.debug,
appId: info.appId,
timestamp: info.timestamp,
nonceStr: info.nonceStr,
signature: info.signature,
jsApiList: info.jsApiList,
});
```
Use inside component.
```js
// ...
mounted() {
this.$wechat.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: this.onWechatFileChoose,
});
},
methods: {
onWechatFileChoose({ localIds }) {
if (window.__wxjs_is_wkwebview) {
let i = 0;
const infos = [];
const next = () => {
if (i < localIds.length) {
this.$wechat.getLocalImgData({
localId: localIds[i],
success: ({ localData }) => {
infos.push({ dataUrl: localData });
i += 1;
next();
},
});
} else {
this.insertInfo(infos);
}
};
next();
} else {
this.insertInfo(localIds.map(localId => ({ src: localId, localId })));
}
},
insertInfo(rawInfos) {
console.log(rawInfos);
},
},
// ...
```