当前位置: 首页 > news >正文

娱乐类网站最吸引人的引流话术

娱乐类网站,最吸引人的引流话术,上海自动化仪表厂,j2ee做网站官方网站: Web Component - Web API 接口参考 | MDN 1. 给一个html文件的路径字符串path, 存储对应path下的template,script,style数据 1) 传入path 2) 使用fetch将path字符串所在的文件找到并返回内容 const res await fetch(path).then(res > res.text()); 3) 使用…

官方网站:

Web Component - Web API 接口参考 | MDN

1. 给一个html文件的路径字符串path, 存储对应path下的template,script,style数据

1) 传入path

2) 使用fetch将path字符串所在的文件找到并返回内容

const res = await fetch(path).then(res => res.text());

3) 使用DOMParser实例的parseFromString方法将至转换为shadowRoot

const parser = new DOMParser();
const doc = parser.parseFromString(res, "text/html"); // shadowRoot

4) shadowRoot支持dom查找元素的方法, 可以找到template, script, style标签元素

5) 根据不同的path, 存放相应的template, script, style

// 动态加载组件并解析
async function loadComponent(path, name) {this.caches = this.caches || {};// 当缓存存在if (!!this.caches[path]) {return this.caches[path]}const res = await fetch(path).then(res => res.text());// 利用DOMParser,生成shaow-rootconst parser = new DOMParser();const doc = parser.parseFromString(res, "text/html");// 解析模板,脚本,样式const template = doc.querySelector("template");const script = doc.querySelector("script");const style = doc.querySelector("style");// 缓存内容this.caches[path] = {template,script,style}return this.caches[path]
}

2. custom-component.js(自定义标签custom-component)

// 容器组件
class CustomComponent extends HTMLElement {async connectedCallback() {console.log("custom-component connected");// 获取组件的path,即html的路径const strPath = this.getAttribute("path");// 加载htmlconst cInfos = await loadComponent(strPath);// Element.attachShadow() 方法给指定的元素挂载一个 Shadow DOM,并且返回对 ShadowRoot 的引用。const shadow = this.attachShadow({ mode: "closed" });// 添加html对应的标签和内容this._addElements(shadow, cInfos);}_addElements(shadow, info) {if (info.template) {shadow.appendChild(info.template.content.cloneNode(true));}if (info.script) {var fn = new Function(`${info.script.textContent}`);// 绑定脚本的this为当前的影子根节点, 防止全局污染fn.call(shadow);}if (info.style) {shadow.appendChild(info.style);}}
}
window.customElements.define("custom-component", CustomComponent);

使用自定义标签custom-component

// 使用示例: renderComponent.call(thisArg, route)
function renderComponent(route) {var el = document.createElement("custom-component");el.setAttribute("path", `/${route.component}.html`);// append可以追加节点和字符串,appendChild只能追加节点;el.id = "_route_";this.append(el);
}

1) 先新建goods.html

<template><div>商品详情-goos</div><div class="product-id">下面商品是????</div>
</template><script>alert('这是商品页!!!')
</script><style>.product-id{color: red;}
</style>

2) 在index.html使用

先引入custom-component.js

然后在index.html的script标签写:

renderComponent.call(document.getElementById('box'), {component: './goods'})

index.html文件代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>index</title><style></style>
</head><body><div id="box"></div>
</body><script src="./custom-component.js"></script><script>renderComponent.call(document.getElementById('box'), {component: './goods'})</script>
</html>

http://www.15wanjia.com/news/28303.html

相关文章:

  • 中山网站建设找阿江百度指数对比
  • 网站建设的什么是开发实施注意什么百度搜索数据查询
  • 心理咨询 网站模版优化大师win10能用吗
  • 网站建设必须要其他后台吗搜索引擎关键词排名优化
  • 网站建设与维护岗位职责seo网站推广专员招聘
  • 做淘宝联盟网站要多少钱合肥网络营销公司
  • 专门做运动装备的网站seo外包公司哪家专业
  • zhi做网站2021年十大热点事件
  • 江苏汇算清缴在哪个网站做最好用的搜索引擎
  • ps个人网站怎么做搜狗网页
  • 二级域名免费网站优化推广哪家好
  • 网站建设综合网站排名怎么优化
  • 男科医院网站开发策划电商运营怎么做如何从零开始
  • 惠州建设集团网站西安网站seo优化公司
  • 中国制造网网站特色百度搜索关键词数据
  • 织梦茶叶网站模板免费下载世界杯最新排名
  • 河北seo网站优化公司软文广告图片
  • 门户网站建设系统北京seo优化外包
  • 我网站正在建设中网络营销的方式和手段
  • 网站后台操作规范汕头网站制作设计
  • 南宁网站建设科技公司seo文章代写平台
  • 哪里长沙网站开发中国没有限制的搜索引擎
  • 建站计划书南京百度
  • drupal 做的网站美国搜索引擎排名
  • 建设厅网站查询电工证件app拉新推广平台
  • 做论坛网站需要备案网络推广工作能长久吗
  • 广告业网站开发开封seo公司
  • 家用云做网站百度推广运营怎么做
  • 大数据政府网站建设seo外包公司优化
  • 旅游网站开发搜索引擎优化面对哪些困境