在小程序样式文件中,如果设置背景图片的路径用的是本地的,就会报错并且显示不出来;如果在wxml文件中使用图片的本地路径作为背景图,则微信开发者工具中可以显示出来,但是运行到手机上显示不出来,解决方法如下:
方法一:
使用网络图片
background: url('https://cdn.ctoku.com/1123123123123e3241.png') no-repeat center;
方法二:
在线搜索图片转Base64编码
http://www.jsons.cn/img2base64/
文章来源:https://www.toymoban.com/news/detail-506385.html
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAOfklEQVR4Xu1dfZAU1RH/9SychQUIu3cVUGLYWfxMMFoxJmqkNBHRCClNouYPo8GUJvhN+QE3h7p+7CygFDGJuYgViZqyIkmMFUj5FdRSDEiSiokpAWVniUEhdTuLcJYWJzedent7SvBu582+mdnZ23lVW7t1192vu99vPl6/fq8JcWtpD1BLWx8bjxgALQ6CGAAxAFrcAy1ufnwHiAHQ4h5ocfPjO0AMgBb3QIubH98BYgC0uAda3Pz4DhADoMU90OLmx3eAGAAt7oEWN79F7gCrEhMzrx5DjnYoiMcR8Tg4NFb8row/Uy80fo/FN1Mva847uwrHbwIu7B/p+BhxAJgwNTshkdh7Ojt0ChGOBiqfI+ocyDcBbGbG5gRpL/Rro9aVt2b31CkrkmwjAgDJzMKzibUZBMxg4NSAPb2WgXVwsL68zXw64L4CF9+0AOhId57mkDYbzHNAOCZwTw3VAWMTiFZr7KzpKeZfaogOip02FQCmTJk/5oO2g+cCfCmAkxRt95t9I0APjel7f+X27cs/8Ft4UPKaAgCTpnV2fMjaXDBfBuCooJzhk9wtIHpwNDkrd27N9/gkMzAxkQdAe9q4gQnzARwWmBeCEfw2MZaXiuayYMT7IzWyAEjpxtcAdAIQ383c1gLI25YpviPXIgeAjmOzY/v39mWJcUPkvKWgEBOWJQ5qy/a8nn1PQYzvrJECQEe6a4aj8RIwvuy7pVEQSNigObSgp5h7MQrqCB0iA4Ck3nU9gZcAaPPZOX0AdoCwA4yd4jcTdmgO76z8TTTGZEejScSYDGA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wrh4ZAHptyxxfJ68SW8MAMAACYx0DpypY0EOgbjA9GvYdoUNfdASDL2awGHiVK/cN2zLdTwZXcFIt1oYCYAAEnasYdIGqfQy8BOA5DbSmZOUCOU5+on7L9ATvm8VEourJTFWdRXFKu5g/Q1mOgoCGA6DyTlDfFLGW2VsI9CSx87hqebVqObo5AM0GeLqCr/+flfgRu5C/xDd5dQqKBACE7tVgkag57PkFysV28eK4A4QdYOwUv5mwQ3N4Z+VvojEmOxpNIq6UoJkMwiTxt2pJGt/1YdCCspUT1UIb3iIDAOGJSthY4yUyhyQ33HP1KEDYoDm0oKeYkyywWU8n3ngiBYAKCI7Nju3f25clxg3eTIk2NROWJQ5qy/a8nn0vSppGDgCDzknphsgnEAUixHczt7UARLkc8R25FlkADHqqml42H8BhkfNebYXeJsbyUtFcFmW9Iw8A4bxKoilrc8F8mVQ1rcZ6fAuIHhxNzsqdW/M9jVXFvfemAMCgGQP7Dg6eC/ClkmXq3T3gH8VGgB4a0/f+yu3bl3/gn9hgJTUVAPZ3xcBeRG02mOfIFK0OxI2MTSBarbGzRjXeEIh+EkKbFgD725bMLDybWJtBwAzF0LKEy7CWgXVwsL68zQy3ZL2Mdh5pRgQA9rd5wtTshERi7+ns0ClEOBqofI7w6JdBclHlfDMzNidIe6FfG7WuvDUrVjJHTBtxABh6ZFYlJmZePYYc7VAQjyPicXBorPhdoWfqhcbvsfhm6mXNeWdX4fhNKuXYmgUhLQKAZhmO8PWMARC+zyPVYwyASA1H+MrEAAjf55HqMQZApIYjfGViAITv80j1GAMgUsMRvjIxAML3eaR6jAEQqeEIX5kYAOH7PFI9xgCI1HCEr0wMgPB9HqkeYwBEajjCVyYGQPg+j1SPMQAiNRzhK/M/Z+O225fK2+EAAAAASUVORK5CYII=') no-repeat center;
方法三:
使用
<image/>
标签文章来源地址https://www.toymoban.com/news/detail-506385.html
<image src="/public/image/photo_sure.png" ></image>
到了这里,关于【微信小程序】不支持使用本地图片设置背景图片解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!