1.首頁往前端傳送
const express = require('express')
const app = express()
//引入express-art-template 用來解析html文件
app.engine('html', require('express-art-template'))
app.use('/js', express.static('js'))
app.use('/img', express.static('img'))
app.use('/css', express.static('css'))
app.use('/views', express.static('views'))
app.use('/node_modules', express.static('./node_modules'))
app.get('/', (req, res) => {
res.render('index.html')
})
app.get('/index.html', (req, res) => {
res.render('index.html')
})
app.get('/gong.html', (req, res) => {
res.render('gong.html')
})
app.get('/an.html', (req, res) => {
res.render('an.html')
})
app.get('/ye.html', (req, res) => {
res.render('ye.html')
})
app.get('/dong.html', (req, res) => {
res.render('dong.html',{data})
})
app.listen(3000, () => console.log('app is runing......'))
2.子頁面向主頁傳輸數據
const data =
title: "公司動態",
article: [
{id: 1,
'articletitle': "標題",
firm:'內容',
date:
},
{id: 2,
'articletitle': "",
firm:'',
date:
const dataOne= {
title: "標題 ”\n",
date: "發表時間:2021-09-12\n",
article: [
{data1:"內容"},
{img1:"圖片網址"},
app.get('/zi.html', (req, res) => {
console.log(req.query.id)
let dataTotal=null
if (req.query.id == 1) {
dataTotal=dataOne
}
if (req.query.id == 2) {
dataTotal = dataTwo
}
if (req.query.id == 3) {
dataTotal = dataThree
}
res.render('zi.html', {dataTotal})
})
app.listen(3000, () => console.log('app is runing......'))
3.圖片大小的修改
在圖片網址后面修改圖片
在.jpg前加一個!寬×高
例如
但是圖片的寬高必須是一致的如400×400.