从聚合物3中的单独html文件导入模板

Nim*_*ebi 8 html javascript polymer es6-modules polymer-3.x

而不是return "HTML CONTENT";我有一个单独的html文件,我想将其导入我的js文件,以返回它的内容,但import template from '/m-chip.html";不起作用.

element.js

import {Element as PolymerElement} from '../node_modules/@polymer/polymer/polymer-element.js';
import template from '/m-chip.html';
export class Mchip extends PolymerElement{
    static get template() {
        return template;
    } 
    constructor() {
        super();
    }
} 
customElements.define("m-chip" ,Mchip)
Run Code Online (Sandbox Code Playgroud)

M-chip.html

<style>
...
</style>

<div>...</div>
Run Code Online (Sandbox Code Playgroud)

如果没有jquery和普通的js,我怎样才能做到这一点?

小智 3

好吧,导入 html 文件目前不是 javascript 能够理解的。但是,您可以使用 webpack 构建项目并添加 html-loader https://github.com/webpack-contrib/html-loader指定如何在 javascript 中处理 html 导入。