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

南昌做兼职的网站设计网站开发设置网页端口

南昌做兼职的网站设计,网站开发设置网页端口,c++语言做网站,莘县网站建设官方网站: 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 templatediv商品详情-goos/divdiv classproduct-id下面商品是????/div /templatescriptalert(这是商品页!!!) /scriptstyle.product-id{color: red;} /style2) 在index.html使用 先引入custom-component.js 然后在index.html的script标签写: renderComponent.call(document.getElementById(box), {component: ./goods}) index.html文件代码 !DOCTYPE html html langenheadmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleindex/titlestyle/style /headbodydiv idbox/div /bodyscript src./custom-component.js/scriptscriptrenderComponent.call(document.getElementById(box), {component: ./goods})/script /html
http://www.hkea.cn/news/14444547/

相关文章:

  • 周大福网站设计特点个人网站备案信息填写
  • 怎么区分营销型和展示型的网站东莞关键词排名推广
  • 网站开发设计书籍wordpress产品参数多图
  • 赣州网站建设好么深圳营销网站建设服务
  • 建设一个地方门户网站福建省住房城乡建设厅网站
  • 手套网站模板建设响应式网站有哪些好处
  • 如何提高网站的点击量自己怎么做网站游戏
  • 免费个人自助建站网站 备案 中国 名字吗
  • 申请个人网站做seo必须有自己网站吗
  • 杭州营销网站建设平台视频网站建设工具
  • iis 网站属性北京亦庄做网站公司
  • 哪些网站做科技专题app开发公司有什么部门
  • 燕赵邯郸网站建设个人网站推广方法
  • 找生产厂家的网站农庄网站
  • 外链是不是把自己的网站信息发布到别人的网站上?wordpress文章引用格式
  • 河南省工程项目信息公示栏电商seo是什么意思啊
  • 阿坝网站设计三亚最新发布
  • 无忧网站建设服务宁波自适应网站建设
  • 如何在阿里巴巴建设网站网站安全认证去哪做
  • 网站设计师的岗位职责外贸公司应该怎样做外贸网站
  • 又一个wordpress网站科研实验室网站建设
  • 主机 可以 多少 网站网站建设意义
  • 小学学校网站中国建设银行网站首页下载
  • 国外设计网站大全网站数据做面板分析
  • 做的网站打印全乱掉了宣传片拍摄计划方案
  • 上海网站开发技术最好公司成都网站建设四易维达
  • 东莞微信网站建设报价国内做网站建设知名的公司
  • 江苏城嘉建设工程有限公司网站工业互联网建设
  • 17网站模板网站建设软件 优帮云
  • flash网站设计概述徐州做网站哪家好