login.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="content">
  3. <u-button type="success" open-type="getUserInfo" @click="loginIn">微信一键登录</u-button>
  4. </view>
  5. </template>
  6. <script>
  7. import {code2Session} from "@/api/login.js"
  8. export default {
  9. components: {
  10. },
  11. data() {
  12. return {
  13. }
  14. },
  15. onShow () {
  16. },
  17. onLoad(option) {
  18. },
  19. methods: {
  20. loginIn () {
  21. let _this = this
  22. // uni.login({
  23. // provider: provider,
  24. // success(result) {
  25. // console.log(result)
  26. // if (result.code) {
  27. // code2Session({
  28. // code: result.code
  29. // }).then(res => {
  30. // if (res.status === '200') {
  31. // _this.$u.vuex('vuex_openid',res.data)
  32. // uni.navigateTo({
  33. // url: '/pages/index/index'
  34. // })
  35. // };
  36. // });
  37. // }
  38. // }
  39. // });
  40. uni.login({
  41. provider: 'weixin',
  42. success: function (loginRes) {
  43. console.log(loginRes); // 返回code
  44. uni.navigateTo({
  45. url: '/pages/index/index'
  46. })
  47. }
  48. })
  49. },
  50. }
  51. }
  52. </script>
  53. <style>
  54. .content{
  55. padding: 0;
  56. display: flex;
  57. align-items: center;
  58. justify-content: center;
  59. }
  60. </style>