vue函数
mounted () {
window.GetOrganization = this.GetOrganization; // 方法赋值给window
},
methods: {
// vue内部方法
GetOrganization: function () {
var data = "";
},
}
<script>
function Get() {
GetOrganization(); // 直接通过window方法去调用methods中对应方法
}
</script>
本文介绍了一种在Vue中将方法挂载到全局Window对象的技术。通过在mounted钩子中将组件的方法GetOrganization赋值给Window,使得该方法可以在页面的任意位置被调用。这种方法提供了组件方法的全局访问性,但同时也可能带来命名冲突的风险。

643

被折叠的 条评论
为什么被折叠?



