1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <template>
- <view class="">
-
- </view>
- </template>
- <script>
- import api from "@/utils/api.js"
- export default {
- data() {
- return {
-
- }
- },
- methods: {
-
- },
- urlTobase64(url) {
- wx.request({
- url: url,
- responseType: 'arraybuffer', //最关键的参数,设置返回的数据格式为arraybuffer
- success: res => {
- //把arraybuffer转成base64
- let base64 = wx.arrayBufferToBase64(res.data);
-
- //不加上这串字符,在页面无法显示的哦
- base64 = 'data:image/jpeg;base64,' + base64
- this.lineBg = base64
- //打印出base64字符串,可复制到网页校验一下是否是你选择的原图片呢
- console.log('base64=>', base64)
- }
- })
- }
-
- }
- </script>
|