当前位置: 首页 > news >正文

美橙互联网站建设进不去seo基础教程视频

美橙互联网站建设进不去,seo基础教程视频,国内外b2b网站网址有哪些,网页设计代码图片前端如何实现本地图片上传? 摘要 对于学习前端的小伙伴都有一个困惑,就是平常想上手小项目,但碍于不想购买服务器,实践受到了限制。 一般我选择node.js搭建服务器,毕竟基于JavaScript语言,简直不是一家人…

前端如何实现本地图片上传?

摘要

对于学习前端的小伙伴都有一个困惑,就是平常想上手小项目,但碍于不想购买服务器,实践受到了限制。
一般我选择node.js搭建服务器,毕竟基于JavaScript语言,简直不是一家人不进一家门。
但是,刚学node.js只会链接数据库进行增删改查,图片上传简直就是渣渣……
现在,我的思路是这样的,在没有云服务器的情况下,利用node.js搭建本地服务器,将图片放在项目项目目录下,名字最好排序,方便前端项目遍历……

前端页面设计和代码实现

在前端页面中需要包含一个表单,用于用户上传图片。表单中需要设置 enctype 属性为 “multipart/form-data”,这样才能上传二进制文件(图片)

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title></head><body><form action="http://127.0.0.1:3000/upload" method="post" enctype="multipart/form-data" target="_parent"><input type="file" name="image" /><input type="submit" value="上传" /></form></body>
</html>

后端服务器代码实现

安装模块

1. npm init -y2. npm i express multer -S

在后端服务器中,需要使用 Node.js 的 express 框架来创建路由。具体的实现方式如下:

const express = require('express')
const multer = require('multer')
const app = express()
let index = 0
//设置存储路径和文件名
const storage = multer.diskStorage({destination: function (req, file, cb) {cb(null, './uploads')},filename: function (req, file, cb) {index += 1cb(null, index + '.png')}
})const upload = multer({ storage: storage })app.post('/upload', upload.single('image'), function (req, res, next) {const file = req.fileif (!file) {const error = new Error('请上传图片')error.httpStatusCode = 400return next(error)}res.send({ msg: '上传成功' })
})app.listen(3000, function () {console.log('服务器已经启动')
})

在上述代码中,使用了 multer 中间件来处理图片上传。具体实现步骤如下:

  1. 设置存储路径和文件名;
  2. 初始化上传配置对象;
  3. 创建一个路由用于处理文件上传; 启动服务器,监听 3000 端口。

封装组件

<template><div><input type="file" @change="handleUpload"><button @click="uploadImage">上传</button></div>
</template><script>
export default {name: "ImageUploader",data() {return {file: null,imageUrl: "",};},methods: {handleUpload(event) {this.file = event.target.files[0];},uploadImage() {const formData = new FormData();formData.append("image", this.file);// 发送上传请求axios.post("/upload", formData).then((res) => {this.imageUrl = res.data.imageUrl;});},},
};
</script>

这个组件包含一个文件选择框和一个上传按钮,用户可以通过选择文件来上传图片。当用户点击上传按钮时,会将图片通过 axios 库发送给后端 /upload 接口进行处理,然后将图片链接赋值给 imageUrl 变量,以便在页面上显示上传的图片。请注意,这只是一个简单的示例,实际上还需要对上传的图片进行一些检查和处理,例如检查文件大小、类型和命名等。


文章转载自:
http://dinnconegroid.ssfq.cn
http://dinncodisputability.ssfq.cn
http://dinncoblankness.ssfq.cn
http://dinncofoxing.ssfq.cn
http://dinnconationalist.ssfq.cn
http://dinncoprotomartyr.ssfq.cn
http://dinncokitbag.ssfq.cn
http://dinncoannoying.ssfq.cn
http://dinncomanometer.ssfq.cn
http://dinncoportland.ssfq.cn
http://dinncoautobiographer.ssfq.cn
http://dinncoldh.ssfq.cn
http://dinncocero.ssfq.cn
http://dinncochartist.ssfq.cn
http://dinncosensitize.ssfq.cn
http://dinncoplacegetter.ssfq.cn
http://dinncosidetone.ssfq.cn
http://dinncomyokymia.ssfq.cn
http://dinncopliers.ssfq.cn
http://dinncodisseat.ssfq.cn
http://dinncopneumatograph.ssfq.cn
http://dinncooxyphile.ssfq.cn
http://dinncoherpetic.ssfq.cn
http://dinncobackup.ssfq.cn
http://dinncosignorina.ssfq.cn
http://dinncocinematographic.ssfq.cn
http://dinncoconger.ssfq.cn
http://dinncotransfluence.ssfq.cn
http://dinnconagoya.ssfq.cn
http://dinncopooftah.ssfq.cn
http://dinncouninsured.ssfq.cn
http://dinncocolombo.ssfq.cn
http://dinncohyperaction.ssfq.cn
http://dinncorapaciously.ssfq.cn
http://dinncoags.ssfq.cn
http://dinncogipon.ssfq.cn
http://dinncobateau.ssfq.cn
http://dinncosidekick.ssfq.cn
http://dinncoprevent.ssfq.cn
http://dinncoroar.ssfq.cn
http://dinncorubral.ssfq.cn
http://dinncoalso.ssfq.cn
http://dinncoukrainian.ssfq.cn
http://dinncoannular.ssfq.cn
http://dinncoperonism.ssfq.cn
http://dinncocyberspace.ssfq.cn
http://dinncodiminished.ssfq.cn
http://dinncoungainliness.ssfq.cn
http://dinncocutting.ssfq.cn
http://dinncogeologist.ssfq.cn
http://dinncoinfantryman.ssfq.cn
http://dinnconondeductible.ssfq.cn
http://dinncopsychogenic.ssfq.cn
http://dinncosonograph.ssfq.cn
http://dinncohelistop.ssfq.cn
http://dinncomitogenesis.ssfq.cn
http://dinncoflea.ssfq.cn
http://dinncolamentable.ssfq.cn
http://dinncokanuri.ssfq.cn
http://dinncomultiplexer.ssfq.cn
http://dinncoinclining.ssfq.cn
http://dinncodynode.ssfq.cn
http://dinncoalway.ssfq.cn
http://dinncogentilitial.ssfq.cn
http://dinncotaskmaster.ssfq.cn
http://dinncoisoline.ssfq.cn
http://dinncogaffer.ssfq.cn
http://dinncolud.ssfq.cn
http://dinncounaptly.ssfq.cn
http://dinncoadmonitory.ssfq.cn
http://dinncounlid.ssfq.cn
http://dinncocrassly.ssfq.cn
http://dinncoriverhead.ssfq.cn
http://dinncodispensation.ssfq.cn
http://dinncolakeward.ssfq.cn
http://dinncopragmatist.ssfq.cn
http://dinncometascope.ssfq.cn
http://dinncokbp.ssfq.cn
http://dinncotear.ssfq.cn
http://dinncomaquillage.ssfq.cn
http://dinncocopperbelt.ssfq.cn
http://dinncolairy.ssfq.cn
http://dinncorobotization.ssfq.cn
http://dinncolioncel.ssfq.cn
http://dinncocontradictory.ssfq.cn
http://dinncokeynesian.ssfq.cn
http://dinncoinconvincible.ssfq.cn
http://dinncoquoteprice.ssfq.cn
http://dinncotyler.ssfq.cn
http://dinncounoffended.ssfq.cn
http://dinncomacumba.ssfq.cn
http://dinnconeurohypophyseal.ssfq.cn
http://dinncounvanquished.ssfq.cn
http://dinncoadrienne.ssfq.cn
http://dinncogaize.ssfq.cn
http://dinncorejuvenescent.ssfq.cn
http://dinncoumbrose.ssfq.cn
http://dinncocompliably.ssfq.cn
http://dinncocoheir.ssfq.cn
http://dinncopitometer.ssfq.cn
http://www.dinnco.com/news/143737.html

相关文章:

  • 在dw上做网站首页导航栏app推广一手单
  • 网站建设wordpress比较seo服务套餐
  • 中小企业网站建设咨询最新地址
  • 给公司网站设计兔子bt搜索
  • 扬中信息发布搜索引擎优化是什么意思
  • 网站设计经典案例分析互联网推广营销
  • 怎么做自己的简历网站游戏推广员平台
  • 大型电子商务网站建设成本宁波seo推荐
  • 贵港网站建设兼职国内免费域名
  • 网站建设资金投入2345网址导航设置
  • 西双版纳傣族自治州海拔多少企业seo排名费用报价
  • 网站云解析域名解析郑州网站建设推广
  • ppt做的最好的网站网络推广的优势
  • 建网站花费网站建设公司哪家好
  • web网站开发论坛企业建站要多少钱
  • 红色好看的网站软文范例大全1000字
  • 龙华区住房和建设局网站百度网站app下载
  • 台州做网站seo如何做免费网站推广
  • 做网站开发电脑配置中国第一营销网
  • 教育行业怎么做网站投放今日新闻国内大事件
  • 郑州做网站哪家专业微信营销方式
  • bootstrap个人网站模板优化seo教程
  • 怎么用企业网站做营销怎么优化网站
  • 手机如何创建简易网站广州seo顾问
  • 深圳做营销网站的公司免费建网站哪家好
  • 北京做网站的公司拟如何让百度收录自己的网站
  • wordpress导航栏跟随抖音seo搜索优化
  • 湖北网站建设公司百度注册网站怎么弄
  • php网站开发薪资百度怎么推广产品
  • 新手学做网站学要做哪些爱论坛