📜  更新头标签元数据 vue - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:40.595000             🧑  作者: Mango

代码示例1
created() {
  fetch('test.json')
    .then(resp => resp.json())
    .then(items => {
      this.items = items;
      const descEl = document.querySelector('head meta[name="description"]');
      const titleEl = document.querySelector('head title');

      descEl.setAttribute('content', items[0]['meta-desc']);
      titleEl.textContent = items[0]['meta-title'];
    })
}