vue页面
<iframe frameborder="0" name="myframe" :src="geturl"></iframe>
<button @click="gethtmlmethod()">调用html的方法</button>
data(){
return{
geturl:"static/myhtml.html"
}
},
methods:{
passtohtml(valu){
console.log("html页面的值:"+valu)
},
gethtmlmethod(){
window.frames["myframe"].init()
}
},
created(){
//调取html方法
window['vueDefinedMyProp']=receiveParams=>{
this.passtohtml(receiveParams)
}
}
html页面(static/myhtml.html)html页面要与src同一目录下,在static文件下
<button οnclick="getvuemethod()">调用vue的方法</button>
<script>
function getvuemethod(){
window.parent['vueDefinedMyProp']('222222')
}
function init(){
alert("我是html页面的方法")
}
</script>