{"id":638,"title":"vue2-cli\uff1a\u6253\u5305\u53ca\u90e8\u7f72","good":0,"bad":0,"hit":830,"created_at":"2024-01-28 10:12:46","content":"

\u7b2c\u4e00\u6b65\uff1a\u6253\u5305\uff0c\u6ce8\u610frouter\u6700\u597d\u7528hash\u6a21\u5f0f,\u8fd9\u91cc\u7528\u7684history\u6a21\u5f0f<\/span><\/p>

npm run build<\/p>

\u4f1a\u5728\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2adist\u6587\u4ef6\u5939<\/p>

<\/p>

\u7b2c\u4e8c\u90e8\uff1a\u90e8\u7f72<\/p>

\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u5728\u5176\u4e2d\u6267\u884c<\/p>

npm init<\/p>

npm i express<\/p>

\u5982\u679c\u975e\u8981\u7528history\u6a21\u5f0f\u90e8\u7f72\uff0c\u8981\u6267\u884c\uff1anpm i connect-history-api-fallback<\/span><\/p>

\u5728\u6b64\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2astatic\u6587\u4ef6\u5939\uff0c\u5c06dist\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u653e\u5230\u6b64\u6587\u4ef6\u5939\u4e2d<\/p>

<\/p>

\u7b2c\u4e09\u6b65\uff1a\u65b0\u5efa\u4e00\u4e2aserver.js\u6587\u4ef6\uff1a<\/p>

const express = require('express')<\/span><\/p>

const history = require('connect-history-api-fallback')<\/span><\/p>

<\/span><\/p>

const app = express()<\/span><\/p>

app.use(history())<\/span><\/p>

app.use(express.static(__dirname+'\/static'))<\/span><\/p>

app.get('\/person',(req,res)=>{<\/span><\/p>

    res.send({<\/span><\/p>

        name:'tom',<\/span><\/p>

        age:18<\/span><\/p>

    })<\/span><\/p>

})<\/span><\/p>

app.listen(5005,(err)=>{<\/span><\/p>

    if(!err) console.log('\u542f\u52a8\u6210\u529f')<\/span><\/p>

})<\/span><\/p>

<\/p>

\u7b2c4\u6b65: node server\u5f00\u542f\u670d\u52a1\u5668<\/p>"}