我必须为支付网关使用两个外部脚本。
现在两者都被放入index.html
file.
但是,我不想在开始时加载这些文件。
仅当用户打开特定组件时才需要支付网关(using router-view
).
有办法实现这个目标吗?
Thanks.
解决这个问题的一个简单有效的方法是将外部脚本添加到 vue 中mounted()
你的组件。我将用谷歌验证码 https://www.google.com/recaptcha/intro/ script:
<template>
.... your HTML
</template>
<script>
export default {
data: () => ({
......data of your component
}),
mounted() {
let recaptchaScript = document.createElement('script')
recaptchaScript.setAttribute('src', 'https://www.google.com/recaptcha/api.js')
document.head.appendChild(recaptchaScript)
},
methods: {
......methods of your component
}
}
</script>
Source: https://medium.com/@lassiuosukainen/how-to-include-a-script-tag-on-a-vue-component-fe10940af9e8 https://medium.com/@lassiuosukainen/how-to-include-a-script-tag-on-a-vue-component-fe10940af9e8
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)