electron中webview使用

2024-02-16 11:00:58 阅读:4 编辑
<template>
    <div>
        <webview
                id="webview"
                autosize="on"
                allowpopups
                :src="url"
                :data-home="url"
                scrollbars="none"
                partition="pdd-modal-webview"
        ></webview>
    </div>

</template>
<script>
    import {ipcApiRoute} from '@/api/main'
    import $ from 'jquery'
    import CodeMirror from './../../components/codemirror'
    import PluginList from './../../components/pluginlist'
    import myMixins from './../../mixins'

    export default {
        data() {
            return {
                url:'https://juejin.cn/',

            };
        },
        watch: {

        },
        mounted: function () {

        },
        methods: {

        }

    };
</script>
<style scoped>
    #webview {
        width: 100vw;
        height: 100vh;
    }
</style>
electron/config/config.default.js
config.windowsOption = {
    title: '神码开发工具',
    width: 980,
    height: 650,
    minWidth: 800,
    minHeight: 650,
    webPreferences: {
      webviewTag: true, //开启webview
      //webSecurity: false, // 跨域问题 -> 打开注释
      contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
      nodeIntegration: true,
      //preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
    },
    frame: true,
    show: false,
    icon: path.join(appInfo.home, 'public', 'images', 'logo-32.png'),
  };