如何在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']
},
nuxt.js服务端渲染使用flexible.js和postcss-px2rem实现移动端自适应—淘宝弹性布局方案(750px设计稿)
添加链接描述