font-size的控制 em与px的终极PK!转载信息:Author:52css Data:2007-05-14

本文探讨了网页设计中px与em两种单位的区别及应用场景,特别是如何利用em实现响应式字体大小调整,解决了IE浏览器下字体放大的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里引用的是Jorux的“95%的中国网站需要重写CSS”的文章,题目有点吓人,但是确实是现在国内网页制作方面的一些缺陷。我一直也搞不清楚px与em之间的关系和特点,看过以后后确实收获很大。平时都是用px来定义字体,所以无法用浏览器字体放大的功能,而国外大多数网站都可以在IE下使用。因为 


  1. IE无法调整那些使用px作为单位的字体大小; 
  2. 国外的大部分网站能够调整的原因在于其使用了em作为字体单位; 
  3. Firefox能够调整px和em,但是96%以上的中国网民使用IE浏览器(或内核)。 


  px像素(Pixel)。相对长度单位。像素px是相对于显示器屏幕分辨率而言的。
  em是相对长度单位。相对于当前对象内文本的字体尺寸。如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸。 


  任意浏览器的默认字体高都是16px。所有未经调整的浏览器都符合: 1em=16px。那么12px=0.75em, 10px=0.625em。为了简化font-size的换算,需要在css中的body选择器中声明Font-size=62.5%,这就使em值变为16px*62.5%=10px, 这样12px=1.2em, 10px=1em, 也就是说只需要将你的原来的px数值除以10,然后换上em作为单位就行了。 

  em有如下特点: 

  1. em的值并不是固定的; 
  2. em会继承父级元素的字体大小。 


  所以我们在写CSS的时候,需要注意: 
  1. body选择器中声明Font-size=62.5%; 
  2. 将你的原来的px数值除以10,然后换上em作为单位; 
  3. 重新计算那些被放大的字体的em数值。避免字体大小的重复声明。 


  也就是避免1.2 * 1.2= 1.44的现象。比如说你在#content中声明了字体大小为1.2em,那么在声明p的字体大小时就只能是1em,而不是1.2em, 因为此em非彼em,它因继承#content的字体高而变为了1em=12px。 

  但是12px汉字例外,就是由以上方法得到的12px(1.2em)大小的汉字在IE中并不等于直接用12px定义的字体大小,而是稍大一点。这个问题Jorux已经解决,只需在body选择器中把62.5%换成63%就能正常显示了。原因可能是IE处理汉字时,对于浮点的取值精确度有限。不知道有没有其他的解释。

 

 

 

 

aj.great  [2007-06-20 10:08 PM]
用关键字设置字体也不错 
例如: body  {font-size:small;}
配合使用百分比就灵活多了
例如: h1 {font-size:200%;} 
          ul a {font-size:80%;}

个人感觉em用于设置margin和padding时作用更突出

 

 

 

 

 

<!doctype html> <!DOCTYPE html><html><head><meta charset="utf-8"> <meta name="Author" content="Noah"> <meta name="Keywords" content=""> <meta name="Description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="favicon" href="favicon.ico"> <title>BA综合发布页</title> <meta name="keywords" content="欢迎使用BA综合"> <meta name="description" content="欢迎使用BA综合"> <style>@font-face{font-family:iconfont;src:url(//at.alicdn.com/t/font_1706200_3sgw4esvyq9.eot?t=1584846914425);src:url(//at.alicdn.com/t/font_1706200_3sgw4esvyq9.eot?t=1584846914425#iefix) format('embedded-opentype'),url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAPcAAsAAAAACEAAAAOQAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCDMgqDVIMaATYCJAMUCwwABCAFhG0HUhswBxEVnPHIfiZkcgn7O+8oo66bEbK2OpSJxjfBA+X1vslMtll8iBW0KuzdSry1J/JGpwASAA0EaO7O95urXT4WOkKV5Nojj7b4hwrpy2SO/v97p78xLfvYuvYslzWHLex8DDAOpEDHnGQljg3TC+cUPEjbIQAHqRRD1GvQzI2BgvQTgBjYr083jJQNVcMRGEZbyVSVKhajY2hztCvAIv178YYywgANXUJ2atW7fk9qmZi1ZMCSjnILC8fbDUAHJFAMUCCGl/oGIm2uGBKHP1RRC3BgoKGZmLxVUbOWZcWqHRkc9A8PBBKFBsIGKXUBUAvlFZhwBAGmhiDBLIqgwKyVRwPuKwAOWAjCWUxL9mpIWOWKcikVmuwiF0+49sx9/bnn5gvfDdO/at6eQHTP5dHLd8Z6V67btSPG061Q523w0S5OzYETx4QbT9zXbnmuP/bdvOsL9lwR2D031utePndvMM7nXRncNy/G4xvlEveE69fc4Tdu+AbcnOdxa4E98/bFyZV75+5WxGRRnfY0cEulpaqbVCzNtxTEU1P1m2J4tFGwJ7VcytpevcrWOXd44oCjAyZu3DXRvQxryi09PV2/BcVQIlRxZPWvAFhMXkb1qQ3bHPFvOVXxWI1TjTLPFjtT5smFsAtxVqK82CcvekwcsbMOHDh4wOBxYw4eZI+NVR+A6Vmx4bGz1ZI0XFw1r0mlXm20lW5RpWd+s0u/ijYZwarmHJsZVi+tXKjMlU2rm186Hlk6tFxaPfwAWLPk3380K2u4Qm6xtmaprTL4b/dj0Nu/F+qwat8MpwLgzvpfdbSsPbbVBj9Ijy//kxa1tAb7qAqUxK4rT8490qpVpxGATiESBDT4aTX/LxTJg3H0MbPIZMAgJgaNIqSAxCCbpGjFQMdJObBhUBMcFKXhbCdRDEcilB0oZAYAQTiHQCOU4yAJ5ypJ0e6DTizvwEa4kODAK6KWdJIrLP1uHgWtYqDuj3zPi2FOvTHlb7BpaiWp1NwvSPRJKrMiW3zFAhljRPy2laohIzzTC9gN08S0Cgf0mjnV9ZLnpuxDWc/z5oZHQasYqPsj3/NiZGO9yX3/DTZNrdQQ+qJfkOjbpzIrWpBedUsrwrXcEr9tpWrICM/0AjyYaI5pLe8U0GvmemTWS47qmba6bH7D/IybAAdkZV1oQgoldGHjYViCYPl3WKxb86g+On/sE/+kc/CLtS1vNg==') format('woff2'),url(//at.alicdn.com/t/font_1706200_3sgw4esvyq9.woff?t=1584846914425) format('woff'),url(//at.alicdn.com/t/font_1706200_3sgw4esvyq9.ttf?t=1584846914425) format('truetype'),url(//at.alicdn.com/t/font_1706200_3sgw4esvyq9.svg?t=1584846914425#iconfont) format('svg')}.iconfont{font-family:iconfont!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-querenzhengque:before{content:"\e600"}.icon-tishi:before{content:"\e640"}.icon-cuowu:before{content:"\e602"}.icon-jinggao:before{content:"\e62b"}*{box-sizing:border-box;margin:0;padding:0;font-weight:300}body,body ::-webkit-input-placeholder{font-family:Source Sans Pro,sans-serif;color:#fff;font-weight:300}body :-moz-placeholder,body ::-moz-placeholder{font-family:Source Sans Pro,sans-serif;color:#fff;opacity:1;font-weight:300}body :-ms-input-placeholder{font-family:Source Sans Pro,sans-serif;color:#fff;font-weight:300}a{text-decoration:none}.wrapper{background: #01a982; background: linear-gradient(to bottom right,#01a982 0,#60ae80 100%); overflow: hidden;}.bg-bubbles,.wrapper{position:absolute;left:0;width:100%;height:100%}.bg-bubbles{top:0;z-index:1}.bg-bubbles li{position:absolute;list-style:none;display:block;width:40px;height:40px;background-color:hsla(0,0%,100%,.15);bottom:-160px;animation:square 25s infinite;transition-timing-function:linear}.bg-bubbles li:nth-child(1){left:10%}.bg-bubbles li:nth-child(2){left:20%;width:80px;height:80px;animation-delay:2s;animation-duration:17s}.bg-bubbles li:nth-child(3){left:25%;animation-delay:4s}.bg-bubbles li:nth-child(4){left:40%;width:60px;height:60px;animation-duration:22s;background-color:hsla(0,0%,100%,.25)}.bg-bubbles li:nth-child(5){left:70%}.bg-bubbles li:nth-child(6){left:80%;width:120px;height:120px;animation-delay:3s;background-color:hsla(0,0%,100%,.2)}.bg-bubbles li:nth-child(7){left:32%;width:160px;height:160px;animation-delay:7s}.bg-bubbles li:nth-child(8){left:55%;width:20px;height:20px;animation-delay:15s;animation-duration:40s}.bg-bubbles li:nth-child(9){left:25%;width:10px;height:10px;animation-delay:2s;animation-duration:40s;background-color:hsla(0,0%,100%,.3)}.bg-bubbles li:nth-child(10){left:90%;width:160px;height:160px;animation-delay:11s}@keyframes square{0%{transform:translatey(0)}to{transform:translatey(-700px) rotate(600deg)}}@media (max-width:500px){.container h1{font-size:60px}form button,form input{width:500px}}.main{padding:50px 0;z-index:999;position:relative}.main h1{font-size:40px;text-align:center;color:#fff;margin-bottom:30px;text-transform:uppercase}.content{margin:0 auto;width:28%;background:#fff;border-radius:5px}p.footer{font-size:16px;text-align:center;color:#fff;font-weight:500;margin-top:30px}p.footer a{color:#55acee}p.footer a:hover{color:#000;transition:.5s all;-webkit-transition:.5s all;-moz-transition:.5s all;-o-transition:.5s all;-ms-transition:.5s all}.content-top h2{font-size:22px;color:#fff;text-align:center;background:#02a982;padding:12px 0;border-radius:5px}.content-top p{text-align:center;font-size:16px;color:#000;margin-top:15px}.content-top ul li{display:block;font-size:15px;color:#000;line-height:1.8em;padding:1em 0 1em 1em;border-bottom:1px solid #e2e0de}.content-top ul li a{color:#000;font-weight:400}.content-top ul li a i{color:#02a982;font-style:normal;display:block;margin:2px 0}.content-top ul li span{display:block;color:#999}.content-top{padding:1.5em}.content-top p a{color:#55acee;margin-left:5px}@media (max-width:1366px){.content{width:31%}}@media (max-width:1280px){.content{width:32%}}@media (max-width:1080px){.content{width:38%}.main h1{font-size:36px}.content-top h2{font-size:20px;padding:10px 0}.content-top p,.content-top ul li,p.footer{font-size:14px}}@media (max-width:800px){.main h1{font-size:34px}.content{width:46%}}@media (max-width:768px){.main{padding:90px 0}.main h1{margin-bottom:55px}p.footer{margin-top:75px}}@media (max-width:736px){.main{padding:70px 0}.main h1{margin-bottom:45px}.content{width:53%}p.footer{margin-top:50px}}@media (max-width:667px){.main h1{font-size:32px;margin-bottom:35px}.main{padding:60px 0}.content{width:57%}.content-top h2{font-size:18px}}@media (max-width:600px){.main h1{font-size:30px}.content-top{padding:1em}.content{width:62%}}@media (max-width:568px){.content{width:68%}}@media (max-width:480px){.content{width:78%}.main h1{font-size:28px}p.footer{margin-top:42px}}@media (max-width:414px){.content-top h2{font-size:16px}.content{width:85%}.main{padding:50px 0}p.footer{line-height:1.8em;margin:42px auto 0;width:85%}}@media (max-width:384px){.main h1{font-size:27px}.content,p.footer{width:90%}p.footer{margin:32px auto 0}}@media (max-width:375px){.main h1{font-size:26px;margin-bottom:25px}.main{padding:45px 0}.content,p.footer{width:92%}.content-top h2{padding:8px 0}}@media (max-width:320px){.main h1{font-size:24px;margin-bottom:30px}.content-top ul li{padding:1em 0 1em 1em;background-size:13%!important}.content-top{padding:1.2em}.content-top p,.content-top ul li,p.footer{font-size:13px}.content,p.footer{width:90%}}@media(max-width:500px){.bg-bubbles, .wrapper{height:auto;}}</style> </head> <body> <div id="all"> <div class="wrapper"> <div class="main"> <h1>BA综合发布页</h1> <div class="content"> <div class="content-top"> <h2>请 Ctrl+D 收藏本页到浏览器收藏夹</h2> <ul> <li> 授权查询 <a href="http://bamxys.kvlzv.top/query.php" target="_blank"><i>http://bamxys.kvlzv.top/query.php</i></a> </li> <li> 使用卡密 <a href="http://bamxys.kvlzv.top/auth.php" target="_blank"><i>http://bamxys.kvlzv.top//auth.php</i></a> </li> <li> 代理登录 <a href="http://bamxys.kvlzv.top/agent" target="_blank"><i>http://bamxys.kvlzv.top/admin</i></a> </li> <li> 自助购买 <a href="https://fk.jiuykj.com/shop/RXTool" target="_blank"><i>https://fk.jiuykj.com/shop/RXTool</i></a> </li> <li> BA系列插件插件下载 <a href="https://www.123912.com/s/ZFvDVv-5K8Sv" target="_blank"><i>https://www.123912.com/s/ZFvDVv-5K8Sv </li> <li> <span>近期部分国产浏览器屏蔽网址,电脑请安装<a href="https://www.google.cn/chrome/" target="_blank">chrome浏览器</a>访问,手机请安装<a href="https://www.xbext.com/" target="_blank">X浏览器</a>访问。<span> </span></span></li></ul> </div> </div> <p class="footer">© 2025 BA综合发布页. All Rights Reserved</p> </div> <ul class="bg-bubbles"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </div> </div> </div> <br> <div style="display:none"><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1279597563&web_id=1279597563"></script></div> </body></html> 请你给这段代码页脚加一个网站已运行
07-29
接下来我将提供两个Vue组件的代码,第一个是父组件postDetail.vue 第二个是子组件FeishuShare.vue。我尝试将父组件的post[]属性传递给子组件中并保存为sharedPost,请问为什么传递的是空值(父组件的post不是空值) 第一段代码 <template> <!-- 帖子信息详情 --> <div class="detail-container"> <div class="detail"> <div class="title-container"> <h2 class="title">{{ post.title }}</h2> <!-- 分享按钮 --> <FeishuShare /> <span class="date">{{ post.createDate }} 作者:<span class="author"> {{ post.author ? post.author.username : '匿名' }} </span></span> </div> <div class="summary-container"> <font class="summary"> {{ post.summary }} </font> </div> <!-- 标签展示区域 --> <div v-if="post.tags" class="tags-container"> <el-tag v-for="tag in post.tags.split(/[; ;]/).map((tag) => tag.trim())" :key="tag" style="margin-right: 10px; margin-bottom: 5px; white-space: normal; height: auto;" >{{ tag }}</el-tag> </div> <div class="content-container"> <Editor v-model="post.content" style="height: 500px; overflow-y: hidden;" :default-config="editorConfig" :mode="mode" @onCreated="onCreated" /> </div> </div> <!-- 评论区域 --> <div class="comment"> <div class="comment-list-container"> <div v-if="comments.length === 0" class="no-comments">暂无评论</div> <div v-else> <div v-for="comment in comments" :key="comment.id" class="comment-item" > <div class="comment-item-content"> <div class="comment-header"> <div class="comment-header-left"> <el-avatar :size="40" icon="el-icon-user-solid" alt="评论者头像" :src="comment.isAnonymous? null : comment.author.avatar" class="comment-avatar" /> <span class="comment-author">{{ comment.isAnonymous? '匿名' : comment.author.username }}</span> </div> <div class="comment-header-right"> <span class="comment-date">发表于:{{ comment.updateTime }}</span> <el-button type="text" size="mini" class="reply-btn" @click="handleReply(comment)" >回复</el-button> <div v-if="replyTo === comment.id" class="replying-indicator"> 正在回复此评论 </div> <!-- 显示回复关系 --> <div v-if="comment.parentComment" class="reply-to"> 回复 <span class="reply-to-user">@{{ comment.parentComment.isAnonymous ? '匿名用户' : comment.parentComment.author.username }}</span> </div> <p class="comment-content"> <span v-if="comment.parentCommentId" class="reply-to"> 回复 @{{ getReplyToUsername(comment) }}: </span> <span v-html="comment.content" /> </p> </div> </div> </div> </div> <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="fetchPostComments" /> </div> </div> </div> <div class="comment-form"> <!-- 发表评论表单 --> <el-form ref="commentForm" :model="newComment" > <p v-if="!replyTo">发表评论</p> <p v-else> 正在回复 <span class="replying-to">@{{ replyingToUsername }}</span> <el-button type="text" size="mini" @click="cancelReply">取消回复</el-button> </p> <el-form-item class="comments-content"> <!-- <el-input v-model="newComment.content" type="textarea" placeholder="请输入内容" rows="8" maxlength="1000" show-word-limit /> --> <div style="border: 1px solid #ccc;"> <Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :default-config="toolbarConfig2" :mode="mode" /> <Editor v-model="newComment.content" style="height: 500px; overflow-y: hidden;" :default-config="editorConfig2" :mode="mode" @onCreated="onCreated" /> </div> </el-form-item> <el-form-item label="匿名"> <el-switch v-model="newComment.isAnonymous" active-text="是" inactive-text="否" /> </el-form-item> <el-form-item> <el-button type="primary" @click="submitComment">提交评论</el-button> </el-form-item> </el-form> </div> </div> </template> <script> import { Editor, Toolbar } from '@wangeditor/editor-for-vue' import waves from '@/directive/waves' // waves directive import Pagination from '@/components/Pagination' import store from '@/store' import { addComment, getPostComments, getPostDetail } from '@/api/post' import { getToken } from '@/utils/auth' import FeishuShare from './FeishuShare.vue' export default { components: { Pagination, Editor, Toolbar ,FeishuShare}, // 注册组件 directives: { waves }, data() { var config = { placeholder: '请输入内容....', MENU_CONF: {} } config = this.setConfig(config) return { editor: null, toolbarConfig2: {}, editorConfig: { placeholder: '', readOnly: true }, editorConfig2: config, mode: 'default', // or 'simple' // 以上为富文本编辑器参数 postId: 0, post: { id: 0, title: '', content: '', author: '', createDate: '', updateDate: '', userId: 0, avatar: '', tags: '' }, comments: [], replyTo: null, // 当前回复的评论ID replyingToUsername: '', // 正在回复的用户名 newComment: { id: 0, isAnonymous: false, content: '', parentCommentId: null }, total: 0, listLoading: true, listQuery: { page: 1, size: 10 }, userInfoMap: {} // editorConfig: { // height: 150, // showUpload: false, // menubar: '', // toolbar: [ // 'undo redo forecolor backcolor bold italic underline strikethrough alignleft aligncenter alignright' // ] // } } }, created() { this.postId = Number(this.$route.params.id) if (!this.postId || isNaN(this.postId) || this.postId <= 0) { this.$message.error('帖子ID无效') this.$router.push('/') return } this.newComment.id = this.postId this.fetchPostDetails() this.fetchPostComments() }, methods: { setConfig(editorConfig) { var temp if (store.getters.token) { temp = getToken() } editorConfig.MENU_CONF['uploadImage'] = { server: '/api/post/upload/image', maxFileSize: 10 * 1024 * 1024, headers: { 'X-Token': temp } } editorConfig.MENU_CONF['uploadVideo'] = { server: '/api/post/upload/video', maxFileSize: 100 * 1024 * 1024, headers: { 'X-Token': temp } } editorConfig.MENU_CONF['codeSelectLang'] = { codeLangs: [ { text: 'CSS', value: 'css' }, { text: 'HTML', value: 'html' }, { text: 'XML', value: 'xml' } ] } return editorConfig }, onCreated(editor) { this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错 }, beforeDestroy() { const editor = this.editor if (editor == null) return editor.destroy() // 组件销毁时,及时销毁编辑器 }, fetchPostDetails() { getPostDetail(this.postId) .then((response) => { this.post = response.data if (!this.post.summary) { this.post.summary = '无概要信息' } this.fetchPostComments() }) .catch((error) => { console.error('获取帖子详情失败:', error) this.$message.error('获取帖子详情失败') }) }, getReplyToUsername(comment) { const parentComment = this.comments.find(c => c.id === comment.parentCommentId) return parentComment ? (parentComment.isAnonymous ? '匿名用户' : parentComment.author.username) : '' }, fetchPostComments() { const data = { id: this.postId, page: this.listQuery.page, size: this.listQuery.size } getPostComments(data) .then((response) => { this.comments = response.data.content this.total = response.data.totalElements this.listLoading = false setTimeout(() => { this.listLoading = false }, 1.5 * 1000) }) }, handleReply(comment) { this.replyTo = comment.id this.replyingToUsername = comment.isAnonymous ? '匿名用户' : comment.author.username this.newComment.parentCommentId = comment.id this.$nextTick(() => { this.$refs.commentForm.$el.querySelector('textarea').focus() }) }, cancelReply() { this.replyTo = null this.replyingToUsername = '' this.newComment.parentCommentId = null }, submitComment() { this.newComment.id = this.postId if (!this.newComment.content.trim()) { this.$message.error('评论内容不能为空') return } addComment(this.newComment) .then((response) => { this.$message.success(this.replyTo ? '回复成功' : '评论成功') this.newComment.content = '' this.newComment.parentCommentId = null this.replyTo = null this.replyingToUsername = '' this.fetchPostComments() }) .catch((error) => { this.$message.error('发布评论失败,请稍后重试') console.error(error) }) } } } </script> <style lang="scss" scoped> .detail-container { padding:20px; background-color: #f7f8fa; min-height: inherit; .detail { background-color: white; padding: 20px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); .tags-container { margin: 10px 0; padding: 10px 0; border-top: 1px solid #eee; border-bottom: 1px solid #eee; display: flex; flex-wrap: wrap; align-items: center; } .title-container { display: flex; flex-direction: column; align-items: center; justify-content: center; margin-bottom: 20px; .title { color: #3e9ece; margin-bottom: 10px; text-align: center; word-break: break-word; } .date { font-size: 12px; text-align: center; line-height: 20px; color: #999; } .author { font-size: 14px; color: black; } } .summary-container{ border: #ebebeb 1px solid; background: #f8f8f8; font-size: 12px; margin: 20px 0 10px; padding: 10px; line-height: 20px; text-indent: 2em; border-radius: 4px; .summary { color: #003048; } } .content-container { margin: 20px 0; padding-bottom: 20px; .content { max-height: none; overflow-y: auto; word-break: break-word; line-height: 1.6; } } } .comment { .reply-to { color: #67c23a; font-weight: bold; margin-right: 5px; } .replying-indicator { color: #67c23a; font-size: 12px; margin: 5px 0; padding: 3px 8px; background-color: #f0f9eb; border-radius: 4px; display: inline-block; } background: white; border: 1px solid #ebeef5; border-radius: 4px; padding: 20px; margin-top: 20px; .comment-list-container { overflow-y: auto; .no-comments { text-align: center; color: #999; padding: 20px; } .comment-item { margin-bottom: 15px; border-bottom: 1px solid #ebeef5; padding-bottom: 15px; &:last-child { border-bottom: none; padding-bottom: 0; } .comment-header { display: flex; align-items: flex-start; justify-content: space-between; } .comment-header-left { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; flex-grow: 1; gap: 10px; min-width: 80px; } .comment-header-right { display: flex; flex-direction: column; align-items: flex-start; flex-grow: 20; margin-left: 20px; } .comment-avatar { width: 40px; height: 40px; border-radius: 50%; } .comment-author, .comment-date { font-size: 12px; color: #999; } .reply-to { font-size: 12px; color: #666; margin: 5px 0; .reply-to-user { color: #409EFF; font-weight: bold; } } .comment-content { margin-top: 5px; word-break: break-word; line-height: 1.6; } } } } .comment-form { margin-top: 20px; padding: 20px; background: white; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); .replying-to { color: #409EFF; font-weight: bold; margin: 0 5px; } } } </style> <style src="@wangeditor/editor/dist/css/style.css"></style> 第二段代码 <template> <div class="feishu-share-btn"> <el-button class="share-btn" type="primary" size="small" icon="el-icon-share" @click="dialogVisible=true;fetchAllUsers()" > shareToYesv </el-button> <el-dialog title="分享" :visible.sync="dialogVisible" width="30%" :before-close="handleClose"> <div class="mainbody"> <el-select v-model="value" filterable placeholder="请输入姓名/群组名"> <el-option v-for="item in options" :key="item.uid" :label="item.username" :value="item.uid"> </el-option> </el-select> </div> <span slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">取 消</el-button> <el-button type="primary" @click="dialogVisible = false,handleShare()">确 定</el-button> </span> </el-dialog> </div> </template> <script> import Axios from 'axios'; import { findAllUsers } from '@/api/user'; import { options } from 'dropzone'; import { sharePost } from '@/api/post'; import PostDetail from './postDetail.vue'; export default { props:['postInfo'], data() { return { dialogVisible: false, options:[], value: '', sharedUserId:'', sharedPost:this.$parent.post, }; }, methods: { handleClose(done) { this.$confirm('确认关闭?') .then(_ => { done(); }) .catch(_ => {}); }, async handleShare(){ try{ if(this.value=='') { console.log('please select'); } console.log(this.sharedPost); this.sharedUserId=this.value; const response=await sharePost(sharedPost,sharedUserId) }catch(error) { console.log('分享失败'); } }, async fetchAllUsers(){ try{ const response=await findAllUsers(); //List<User> fetchResult; //fetchResult=response.data; this.options=response.data; //删除admin this.options=this.options.filter(item=>item.username!='admin'); }catch(error){ console.error('获取分享列表失败'); } }, mounted:{ } } }; </script> <style> .feishu-share-btn { min-width: 100%; height: 40px; position: relative; display:flex; justify-content:flex-end; } .share-btn { position: relative; right: 10px; top: 10px; } </style>
最新发布
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值