代码拉取完成,页面将自动刷新
<script src ="./web-report-vue-min.js"></script>
<script defer>
window.Performance({
domain: `http://report.com/api/v1/report/web`, //此处的report.com指你自己部署的域名,假如是本机启动填127.0.0.1
add: {
appId: "ZzdSi3P1683682161087XXX",
},
});
</script>
这里向大家分享一下不同环境下使用的方法:
VUE_APP_BASE_URL=/abc/index
<script src="<%= VUE_APP_BASE_URL %>/cdn/sdk/web-report-axios.min.js"></script>
<script defer>
window.Performance({
domain: '<%= VUE_APP_BASE_URL %>/api/v1/report/web',
add: {
appId: 'Ac3pkKd1675993494568',
},
});
</script>
Vue3: 可以在 .env.build 等环境配置文件配置环境变量,例如: VITE_BUILD_HOST = 'http://xxxxx:7001'
然后在Vite.config.ts中新增插件:createHtmlPlugin -> npm install createHtmlPlugin -D。然后在plugins中配置以下代码
createHtmlPlugin({
minify: true,
pages: [
{
// entry: "src/main.ts",
filename: "index.html",
template: "index.html",
injectOptions: {
data: {
// title: "index",
injectScript: `<script type ="module" src="/src/utils/inject.ts" defer></script>`,
},
},
},
],
}),
在src下的utils文件夹新增文件inject.ts
window.Performance({
domain: `${window._process_env.VITE_BUILD_HOST}/api/v1/report/web`,
add: {
appId: "ZzdSi3P1XXXX2161087",
},
});
这样就可以动态的引入各个环境的域名前缀,部署到各个环境啦。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。