nuxt nuxt.config.js引入rem.js问题

版权声明:干一行、爱一行、爱学习、爱分享! https://blog.csdn.net/weixin_36951197/article/details/82790602

如何在nuxt的head页面引入rem.js;

  • 首先在nuxt.config.js文件里定义 常量rem
const rem = '!function(e){var t,n=document,i=window,o=n.documentElement;function u(){var t=o.getBoundingClientRect().width/e*100;o.style.fontSize=t+"px"}u(),i.addEventListener("resize",function(){clearTimeout(t),t=setTimeout(u,300)},!1),i.addEventListener("pageshow",function(e){e.persisted&&(clearTimeout(t),t=setTimeout(u,300))},!1)}(750);';
  • 在head里用script:[]引入一下,加入 __dangerouslyDisableSanitizers: [‘script’]
    后,不会再对rem做转义了,该字段使用需慎重!
  head: {
	  script: [
		  { innerHTML: rem, type: 'text/javascript', charset: 'utf-8'}
	  ],
	  __dangerouslyDisableSanitizers: ['script']
  },
  • 效果如下:
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_36951197/article/details/82790602