vue.js中文乱码是因为响应头默认编码类型为GBK,而文件为UFT-8类型导致的,其解决办法就是设置响应头编码类型为“charset=UTF-8”即可。

本教程操作环境:windows7系统、vue2.0版,DELL G3电脑。
【相关文章推荐:vue.js】
Vue2.0流式渲染中文乱码问题
在参照vue2.0中文官方文档学习服务端渲染之流式渲染时,因为响应头默认编码类型为GBK,而文件为UFT-8类型,所以出现了中文乱码问题。
立即学习“前端免费学习笔记(深入)”;
解决办法:设置响应头编码类型即可
response.setHeader("Content-type", "text/html;charset=UTF-8");
server.get('*',function(request,response){
response.setHeader("Content-type", "text/html;charset=UTF-8");
var stream = renderer.renderToStream(require('./assets/app')())
response.write(preAppHTML)
stream.on('data',function(chunk){
response.write(chunk)
})
stream.on('end',function(){
response.end(postAppHTML)
})
stream.on('error',function(error){
console.log(error)
return response.status(500).send('Server Error')
})
})以上就是如何解决vue.js中文乱码问题的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号