简体   繁体   中英

Included JS in the index.html is not working in main.js in VUE project

Below is the index.html of a simple VueJS app. I included the widget from netvibes.com. I have included the widget code under in html file and its working.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:widget="http://www.netvibes.com/ns/">

<head>
  <!-- Application Metas -->
  <title>Hello World sample</title>
  <meta name="debugMode" content="false" />
  <meta name="strictMode" content="false" />
  
  <!-- UWA Environment -->
  <script type="text/javascript" src="https://uwa.netvibes.com/lib/c/UWA/js/UWA_Standalone_Alone.js"></script>

  <!-- Application Preferences -->
  <widget:preferences>
  </widget:preferences>

  <script>
    var MyWidget = {
      onLoad: function () {
        widget.setBody('Hello World!');
      }
    };
    widget.addEvent('onLoad', MyWidget.onLoad);
  </script>
</head>

<body>
  <div id="app"></div>
</body>

</html>

输出

But the same "widget" is not getting reflected in the main.js file. I am getting " error 'widget' is not defined no-undef " while compiling. I am using Visual Studio Code.

import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

var mainComponent = null;
function start() {
    widget.setTitle('Find Coach Application');
    mainComponent = createApp(App);
    mainComponent.use(router);
    mainComponent.use(store);
    window.Bus = mainComponent;
    mainComponent.mount("#app");
}

export default function () {
    widget.addEvent("onLoad", () => {
        start();
    });
    widget.addEvent("onRefresh", () => {
        mainComponent.$emit("widgetRefresh");
    });
    widget.addEvent("onResize", () => {
        mainComponent.$emit("widgetResize");
    });
    widget.addEvent("onSearch", (data) => {
        mainComponent.$emit("widgetSearch", data);
    });
}

Please help. Not sure what I am missing here.

main.js尝试访问它:

window.widget

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM