Home>Article>Web Front-end> How to solve the problem of Chinese garbled characters in vue.js

How to solve the problem of Chinese garbled characters in vue.js

藏色散人
藏色散人 Original
2021-01-14 10:21:19 10942browse

vue.js Chinese garbled characters are caused by the default encoding type of the response header being GBK and the file being UFT-8. The solution is to set the response header encoding type to "charset=UTF-8" .

How to solve the problem of Chinese garbled characters in vue.js

The operating environment of this tutorial: windows7 system, vue version 2.0, DELL G3 computer.

[Related article recommendations:vue.js]

Vue2.0 streaming rendering Chinese garbled problem

In reference When vue2.0 Chinese official document is learning server-side rendering and streaming rendering, because the default encoding type of the response header is GBK and the file is UFT-8, the Chinese garbled problem occurs.

Solution: Just set the response header encoding type

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') }) })

The above is the detailed content of How to solve the problem of Chinese garbled characters in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn