【问题标题】:nuxtJS how to make javascript load dynamically by pagenuxtJS如何使javascript按页面动态加载
【发布时间】:2021-07-11 03:31:16
【问题描述】:

我想将此脚本插入到 nuxtJS 项目中,并希望它按页面动态加载。

<!-- LINE Tag Base Code -->
<!-- Do Not Modify -->
<script>
(function(g,d,o){
  g._ltq=g._ltq||[];g._lt=g._lt||function(){g._ltq.push(arguments)};
  var h=location.protocol==='https:'?'https://d.line-scdn.net':'http://d.line-cdn.net';
  var s=d.createElement('script');s.async=1;
  s.src=o||h+'/n/line_tag/public/release/v1/lt.js';
  var t=d.getElementsByTagName('script')[0];t.parentNode.insertBefore(s,t);
    })(window, document);
_lt('init', {
  customerType: 'account',
  tagId: 'xxxxx'
});
_lt('send', 'pv', ['xxxxx']);
</script>
<noscript>
  <img height="1" width="1" style="display:none"
       src="https://tr.line.me/tag.gif?c_t=lap&t_id=xxxxx&e=pv&noscript=1" />
</noscript>
<!-- End LINE Tag Base Code -->

重要的是tagId: 'xxxxx' 这应该是按页面动态更改的。例如,

wwww.sample.com/shop1 will load tagId: 'shop_tag1'
wwww.sample.com/shop2 will load tagId: 'shop_tag2'

【问题讨论】:

    标签: vue.js nuxt.js


    【解决方案1】:

    这是什么类型的追踪器?如果它没有任何方式设置它的应用程序,我猜你需要有一个中间件来运行你的函数并从每个页面中获取动态部分。

    这可能会有所帮助:https://nuxtjs.org/docs/2.x/directory-structure/middleware/ 另外,我确实发现了在 layout 中使用中间件的一些问题,但也许只有我一个人,如果它对你有用,你也可以把你的 js 转储在那里。

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2019-12-02
      相关资源
      最近更新 更多