首页 > 其他分享 >quasar [email protected] ssr Meta插件 使用 title无法reactive的bug

quasar [email protected] ssr Meta插件 使用 title无法reactive的bug

时间:2023-05-18 20:56:04浏览次数:33  
标签:手慢 插件 title quasar detail value content meta

为了使自己的网站SEO更友好,在项目里启用了quasar的Meta插件。但实际使用下来发现文档里的描述不正确。为了动态的更新title和meta信息,文档https://quasar.dev/quasar-plugins/meta 里介绍

Reactive

In the section above, you noticed all of the meta props are “static”. But they can be dynamic (reactive) instead, should you wish. This is how you can manage them just as with a Vue computed property:

// some .vue file
import { useMeta } from 'quasar'
import { ref } from 'vue'

export default {
  setup () {
    const title = ref('Some title') // we define the "title" prop

    // NOTICE the parameter here is a function
    // Under the hood, it is converted to a Vue computed prop for reactivity
    useMeta(() => {
      return {
        // whenever "title" from above changes, your meta will automatically update
        title: title.value
      }
    })

    function setAnotherTitle () {
      title.value = 'Another title' // will automatically trigger a Meta update due to the binding
    }

    return {
      setAnotherTitle
    }
  }
}

但我使用下来,meta的tag信息是动态改变了(ssr模式返回的response里html的meta信息已经改成了相应detail页面的商品信息),但title信息却没有改变(ssr模式返回的response里的html的title没有改变成对应detai页面的商品信息)
代码如下:
  setup() {
    console.log('DetailPage setup');
    const title = ref(
      '好价党 各大电商今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息'
    );
    const meta = reactive({
      description: {
        name: 'description',
        content:
          '好价党 汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,手慢无,秒杀,京东低价,优惠信息',
      },
      keywords: {
        name: 'keywords',
        content:
          '好价党 汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息',
      },
      ogtype: {
        property: 'og:type',
        content: 'product',
      },
      ogurl: {
        property: 'og:url',
        content: '',
      },
      ogtitle: {
        property: 'og:title',
        content:
          '好价党 汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息',
      },
      ogdescription: {
        property: 'og:description',
        content:
          '汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息',
      },
      ogimage: {
        property: 'og:image',
        content: 'https://www.hjdang.com/hjd.png',
      },
      weibocreate: {
        name: 'weibo:webpage:create_at',
        content: '',
      },
      weiboupdate: {
        name: 'weibo:webpage:update_at',
        content: '',
      },
    });

    useMeta(() => {
      return {
        // whenever "title" from above changes, your meta will automatically update
        title: title.value,
        meta: meta,
      };
    });

    function setAnotherTitle(value) {
      title.value = value; // will automatically trigger a Meta update due to the binding
    }

    return {
      setAnotherTitle,
      meta,
    };
  },
  created() {
    console.log('Detail page created');

    this.detail = this._detail;

    this.detailParts = this._detailParts;

    this.bigImages = this._bigImages;

    this.couponInfo = this._couponInfo;
    this.setAnotherTitle(this._detail.title);

    this.meta.description.content =
    this._detail.title + this.detail.emphsis + this.detail.detailBrief;
    let keywords = this.detail.mall;
    if (this._categoryInfo) {
      this._categoryInfo.slice(1).forEach((a) => (keywords += ',' + a));
    }
    this.meta.keywords.content = keywords;
    this.meta.ogtitle.content = this._detail.title;
    this.meta.ogurl.content = 'https://www.hjdang.com/item/detail/' + this.$route.params.urlCode;
    this.meta.ogdescription.content = this.detail.emphsis + this.detail.detailBrief;
    this.meta.ogimage.content = this.detail.mainImageUrl;
    this.meta.weibocreate.content = new Date();
    this.meta.weiboupdate.content = new Date();

  },

但从服务器返回的html里title并没有被改变,但meta.description是被改变了,虽然最终页面上通过Inspect看到的title也是动态改变了,但这个是在前端runtime改变的。为了让搜索引擎看到最终的信息,需要在返回的repsonse里就已经改变

title应该被改成商品的title:PEAK 匹克 。。。才对,但还是初始值
经过我的一番调查,在quasar的guihub上发现了两个帖子,
https://github.com/quasarframework/quasar/discussions/12178#discussioncomment-2046672
https://github.com/quasarframework/quasar/discussions/12388
他的问题和我相反,是title已经动态改变,但meta信息没变。注意到他的useMeta里返回的是title,不是title.value,而meta返回的是myDescription.value,和我的正好相反
import { useMeta } from "quasar";
import { ref } from "vue";
export default {
    setup() {
        const title = ref("First page"); 
        const myDescription = ref({
            name: "description",
            content: "First page quasar app",
        });
        useMeta(() => {
            return {
                title: title,
                titleTemplate: (title) => `${title.value}`,
                meta: {
                    description: myDescription.value,
                },
            };
        });
        const setMetaContent = () => {
            title.value = "Title Changed";
            myDescription.value = {
                name: "description",
                content: "Hey I am changed",
            };
        }
        return {
            setMetaContent,
        };
    },
    serverPrefetch() {
        this.setMetaContent();
    },
    mounted() {
        this.setMetaContent();
    },
};

这是useMega里返回 

            return {
                title: title,
                titleTemplate: (title) => `${title.value}`,
            };

 可以,但返回

      return {
        // whenever "title" from above changes, your meta will automatically update
        title: title.value,
      };
就不可以,也就是不能加 .value,果然改了之后就好了
  setup() {
    console.log('DetailPage setup');
    const title = ref(
      '好价党 各大电商今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息'
    );
    const meta = reactive({
      description: {
        name: 'description',
        content:
          '好价党 汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,手慢无,秒杀,京东低价,优惠信息',
      },
      keywords: {
        name: 'keywords',
        content:
          '好价党 汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息',
      },
      ogtype: {
        property: 'og:type',
        content: 'product',
      },
      ogurl: {
        property: 'og:url',
        content: '',
      },
      ogtitle: {
        property: 'og:title',
        content:
          '好价党 汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息',
      },
      ogdescription: {
        property: 'og:description',
        content:
          '汇聚互联网今日特价 京东,淘宝,天猫,唯品会,支付宝,小米,京喜百元生活费,折扣,优惠券,手慢无,秒杀,低价,优惠信息',
      },
      ogimage: {
        property: 'og:image',
        content: 'https://www.hjdang.com/hjd.png',
      },
      weibocreate: {
        name: 'weibo:webpage:create_at',
        content: '',
      },
      weiboupdate: {
        name: 'weibo:webpage:update_at',
        content: '',
      },
    });


    useMeta(() => {
      return {
        // whenever "title" from above changes, your meta will automatically update
        title: title,
        titleTemplate: (title) => `${title.value}`,
        meta: meta,
      };
    });

    function setAnotherTitle(value) {
      title.value = value; // will automatically trigger a Meta update due to the binding
    }

    // setAnotherTitle('sdsdssds');
    // console.log('title is' + title.value);

    return {
      setAnotherTitle,
      meta,
    };
  },

这样就好了,可能是他们文档写的有问题。

标签:手慢,插件,title,quasar,detail,value,content,meta
From: https://www.cnblogs.com/zjhgx/p/17413266.html

相关文章

  • 【一步步开发AI运动小程序】二、引入插件
    随着人工智能技术的不断发展,阿里体育等IT大厂,推出的“乐动力”、“天天跳绳”AI运动APP,让云上运动会、线上运动会、健身打卡、AI体育指导等概念空前火热。那么,能否将这些在APP成功应用的场景搬上小程序,分享这些概念的红利呢?本系列文章就带您一步一步从零开始开发一个AI运动小程序......
  • 编辑器插件打算添加的功能记录
    1.本地host文件映射[&]2.博客园博客集成[&]3.语音识别并输出文本4.图床功能[&]5.pdf转md6.md转pdf7.代码格式化8.gpt写代码。9.文本翻译10.左右两侧代码比对工具[&]未来可能删减以上内容:编辑器基本功能免费,开启插件功能99元,一次性收费。带[&]为重点集成,有需要加的可以......
  • jenkins插件版本不对,jenkins可能都起不来
    最近公司老的jenkins平台要安装git插件,然后噩梦就开始了由于是不支持访问内网,安装一个git插件就需要离线安装,遇到依赖,就要另外再离线下载依赖,有时候依赖也需要依赖,再继续下一个git插件,本来安装一个,生生下载了十几个依赖 更郁闷的是,由于jenkins版本较老,你也不知道下载插件版......
  • Notepad++ 添加插件Compare
    1在防火墙中打开允许WindowsDefender防火墙--->允许应用或功能通过WindowsDefender防火墙---> 找到对应的应用点击+  打开专用/公用网络没有找到对应的应用--->允许其他应用中添加.exe文件2Notepad++  添加插件Compare=Notepad++---> 插件--->插......
  • WP插件新漏洞使超过 200 万个站点面临网络攻击
    近日,在发现安全漏洞后,敦促WordPress高级自定义字段插件的用户更新版本6.1.6。该问题的标识符为CVE-2023-30777,与反映的跨站点脚本(XSS)案例有关,该案例可能被滥用以将任意可执行脚本注入其他良性网站。该插件有免费版和专业版,活跃安装量超过200万。该问题于2023年5月......
  • leaflet插件leaflet-graticule经度标签格式化问题
    https://github.com/turban/Leaflet.Graticuleimport"leaflet-graticule";L.graticule().addTo(map);解决办法:import"leaflet-graticule";L.LatLngGraticule.prototype.__format_lng_origin=L.LatLngGraticule.prototype.__format_lng;L.LatLngGra......
  • es笔记四之中文分词插件安装与使用
    本文首发于公众号:Hunter后端原文链接:es笔记四之中文分词插件安装与使用前面我们介绍的操作及演示都是基于英语单词的分词,但我们大部分使用的肯定都是中文,所以如果需要使用分词的操作肯定也是需要使用中分分词。这里我们介绍一下如何安装中文分词插件。在介绍安装之前,我们可以......
  • VSCode上的代码变量命名工具插件,让你的开发效率倍增!
    本篇文章主要讲解VSCode上的代码变量命名工具插件chtml代码命名工具的使用。日期:2023年5月15日vscode版本1.78及以上转载地址:https://blog.csdn.net/weixin_46078894,已获作者同意!插件说明CHTML是一款在线的代码命名工具,提供变量命名规则库,可以帮助开发者快速选择合适的变......
  • edge浏览器上可用的AI聊天插件
    WeTab-免费ChatGPT新标签页-MicrosoftEdgeAddons......
  • Boris FX Silhouette 2023 for MAC 影视后期Roto抠像Paint视效合成独立版软件/Adobe插
    业界领先的rotoscoping和painttool,包含了主要的合成功能。Silhouette2023提供400多个VFX节点,包括BorisFXSapphire、MochaPro和ParticleIllusion。十五年来,Silhouette一直是好莱坞大片不可或缺的一部分,最近在《Dune》、《Spiderman:NoWayHome》、《FreeGuy》和《Th......