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

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

藏色散人
Release: 2023-01-13 00:45:06
Original
11100 people have browsed it

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')
    })
})
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template