由於在window對象當中並沒有在vue實例當中定義的方法,需要先在vue實例當中將方法復制給window對象,方可在html頁面的script標簽的當中調用
vue實例中的代碼:
methods:{ abc: function(){ console.log("hello!"); } } mounted() { window.function1 = this.abc; }
script標簽中的代碼:
<script type="text/javascript">
function1();
</script>