upload-photo.vue 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <view class="">
  3. </view>
  4. </template>
  5. <script>
  6. import api from "@/utils/api.js"
  7. export default {
  8. data() {
  9. return {
  10. }
  11. },
  12. methods: {
  13. },
  14. urlTobase64(url) {
  15. wx.request({
  16. url: url,
  17. responseType: 'arraybuffer', //最关键的参数,设置返回的数据格式为arraybuffer
  18. success: res => {
  19. //把arraybuffer转成base64
  20. let base64 = wx.arrayBufferToBase64(res.data);
  21. //不加上这串字符,在页面无法显示的哦
  22. base64 = 'data:image/jpeg;base64,' + base64
  23. this.lineBg = base64
  24. //打印出base64字符串,可复制到网页校验一下是否是你选择的原图片呢
  25. console.log('base64=>', base64)
  26. }
  27. })
  28. }
  29. }
  30. </script>