直接看图先:
代码:
<template>
<div class="iframeBox">
<iframe src="https://www.baidu.com" id="iframe" scrolling="yes" frameborder="0" width="100%" ></iframe>
</div>
</template>
<script>
import $ from 'jquery'
export default {
// components: { $ },
data () {
return {
}
},
mounted(){
/** * iframe-高自适应显示 */
function changeMobsfIframe(){
const iframe = document.getElementById('iframe');
const deviceHeight = document.body.clientHeight;
iframe.style.height = (Number(deviceHeight) - 86) + 'px';
}
changeMobsfIframe();
$(function(){
alert($(window).height())
});
/** * 使用JQ优化后iframe-高自适应显示 */
$(function(){
var autoHeight = $(window).height() - 86
$('#iframe').height(autoHeight)
$(window).resize(function() {
var autoHeight = $(window).height() - 86
$('#iframe').height(autoHeight)
})
});
}
}
</script>
<style>
.iframeBox{position:absolute;width: 100%; top:0px;left: 0px;}
</style>
思路:
1、路由router/index.js写了一个“百度菜单”指向这个iframe模板。
2、在iframe模板跳出去,这里写死了src先不管进阶动态地址。已经满足一个系统套一个系统的需求。
3、在动态获取高的时候,这里写了原生JS,我就想能不能使用JQ简单一点,结果百度了很多方式未果。
第一:vue-element-admin(4.2.1)build下面没有webpack.base.conf文件,注意是压根就没有,所以怎么配置全局JQ?
第二:局部引入直接 import $ from 'jquery'且没有components一下,居然获取高度打印了出来alert($(window).height())。实在不理解。
问题:
虽然实现了想要的结果,但诡异的是JQ引入方式,理想是如何全局引入?
1、我这里的import $ from 'jquery'是局部引入。前提是npm install jquery --save安装了一下。P.S.更诡异的是package.json应该可以看到安装后jquery版本,然而没有jquery影子。
2、用的是饿了么框架 vue-element-admin 版本是4.2.1
直接给结果:
https://stackoverflow.com/que...
1、全局注册main.js
注意:要跑一边npm install jquery