小程序开发中的“业务域名”是指小程序在运行过程中可以访问的外部域名。这些域名通常用于请求数据、加载资源等操作。关闭业务域名意味着小程序将无法再访问这些外部域名。
业务域名的类型主要包括:
原因:
解决方法:
假设我们有一个小程序需要访问一个外部图片资源,我们可以通过以下步骤来关闭业务域名并解决加载问题:
// app.json
{
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
"navigateToMiniProgramAppIdList": [
"your-app-id"
],
"setting": {
"disableScroll": false,
"disableKeyboardAccess": false,
"disableAlert": false,
"disableConfirm": false,
"disablePrompt": false,
"disableShareMenu": false,
"disableShareTimeline": false,
"disableAddToDesktop": false,
"disableAddToHomeScreen": false,
"disableSetStorage": false,
"disableGetStorage": false,
"disableRemoveStorage": false,
"disableClearStorage": false,
"disableGetSystemInfo": false,
"disableGetNetworkType": false,
"disableGetLocation": false,
"disableOpenLocation": false,
"disableChooseLocation": false,
"disableChooseImage": false,
"disableUploadFile": false,
"disableDownloadFile": false,
"disableWebSocket": false,
"disableUploadTask": false,
"disableDownloadTask": false,
"disableBackgroundAudio": false,
"disableRecord": false,
"disablePlayVoice": false,
"disableChooseVoice": false,
"disableStopVoice": false,
"disableTranslateVoice": false,
"disableStartRecord": false,
"disableStopRecord": false,
"disablePlayBackgroundAudio": false,
"disablePauseBackgroundAudio": false,
"disableStopBackgroundAudio": false,
"disableSeekBackgroundAudio": false,
"disableSwitchBackgroundAudio": false,
"disableReplayBackgroundAudio": false,
"disableBackgroundAudioManager": false,
"disableInnerAudioContext": false,
"disableAudioContext": false,
"disableMediaQuery": false,
"disableGetSystemInfoSync": false,
"disableGetNetworkTypeSync": false,
"disableGetLocationSync": false,
"disableOpenLocationSync": false,
"disableChooseImageSync": false,
"disableUploadFileSync": false,
"disableDownloadFileSync": false,
"disableWebSocketSync": false,
"disableUploadTaskSync": false,
"disableDownloadTaskSync": false,
"disableBackgroundAudioSync": false,
"disableInnerAudioContextSync": false,
"disableAudioContextSync": false,
"disableMediaQuerySync": false,
"disableSetStorageSync": false,
"disableGetStorageSync": false,
"disableRemoveStorageSync": false,
"disableClearStorageSync": false,
"disableGetSystemInfoSync": false,
"disableGetNetworkTypeSync": false,
"disableGetLocationSync": false,
"disableOpenLocationSync": false,
"disableChooseImageSync": false,
"disableUploadFileSync": false,
"disableDownloadFileSync": false,
"disableWebSocketSync": false,
"disableUploadTaskSync": false,
"disableDownloadTaskSync": false,
"disableBackgroundAudioSync": false,
"disableInnerAudioContextSync": false,
"disableAudioContextSync": false,
"disableMediaQuerySync": false,
"disableSetStorageSync": false,
"disableGetStorageSync": false,
"disableRemoveStorageSync": false,
"disableClearStorageSync": false,
"disableGetSystemInfoSync": false,
"disableGetNetworkTypeSync": false,
"disableGetLocationSync": false,
"disableOpenLocationSync": false,
"disableChooseImageSync": false,
"disableUploadFileSync": false,
"disableDownloadFileSync": false,
"disableWebSocketSync": false,
"disableUploadTaskSync": false,
"disableDownloadTaskSync": false,
"disableBackgroundAudioSync": false,
"disableInnerAudioContextSync": false,
"disableAudioContextSync": false,
"disableMediaQuerySync": false,
"disableSetStorageSync": false,
"disableGetStorageSync": false,
"disableRemoveStorageSync": false,
"disableClearStorageSync": false
},
"navigateBackMiniProgramAppIdList": [
"your-app-id"
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"sitemapLocation": "sitemap.json",
"style": "v2",
"window": {
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "微信小程序",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
},
"usingComponents": {},
"disableScroll": false,
"disableKeyboardAccess": false,
"disableAlert": false,
"disableConfirm": false,
"disablePrompt": false,
"disableShareMenu": false,
"disableShareTimeline": false,
"disableAddToDesktop": false,
"disableAddToHomeScreen": false,
"disableSetStorage": false,
"disableGetStorage": false,
"disableRemoveStorage": false,
"disableClearStorage": false,
"disableGetSystemInfo": false,
"disableGetNetworkType": false,
"disableGetLocation": false,
"disableOpenLocation": false,
"disableChooseLocation": false,
"disableChooseImage": false,
"disableUploadFile": false,
"disableDownloadFile": false,
"disableWebSocket": false,
"disableUploadTask": false,
"disableDownloadTask": false,
"disableBackgroundAudio": false,
"disableRecord": false,
"disablePlayVoice": false,
"disableChooseVoice": false,
"disableStopVoice": false,
"disableTranslateVoice": false,
"disableStartRecord": false,
"disableStopRecord": false,
"disablePlayBackgroundAudio": false,
"disablePauseBackgroundAudio": false,
"disableStopBackgroundAudio": false,
"disableSeekBackgroundAudio": false,
"disableSwitchBackgroundAudio": false,
"disableReplayBackgroundAudio": false,
"disableBackgroundAudioManager": false,
"disableInnerAudioContext": false,
"disableAudioContext": false,
"disableMediaQuery": false,
"disableGetSystemInfoSync": false,
"disableGetNetworkTypeSync": false,
"disableGetLocationSync": false,
"disableOpenLocationSync": false,
"disableChooseImageSync": false,
"disableUploadFileSync": false,
"disableDownloadFileSync": false,
"disableWebSocketSync": false,
"disableUploadTaskSync": false,
"disableDownloadTaskSync": false,
"disableBackgroundAudioSync": false,
"disableInnerAudioContextSync": false,
"disableAudioContextSync": false,
"disableMediaQuerySync": false,
"disableSetStorageSync": false,
"disableGetStorageSync": false,
"disableRemoveStorageSync": false,
"disableClearStorageSync": false
}
将需要的外部资源(如图片)内嵌到小程序中,或者通过其他方式提供。例如,将图片转换为Base64编码并直接嵌入到代码中:
const imgBase64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...';
然后在小程序中使用该图片:
<image src="{{imgBase64}}" mode="aspectFit"></image>
领取专属 10元无门槛券
手把手带您无忧上云