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

做网站能自己找服务器吗网站seo优化免

做网站能自己找服务器吗,网站seo优化免,wordpress更新后台反应慢,网站开发精品课程目前在工作上有一个需求,就是当文本内容过长时,中间显示省略号…,两端正常展示。我这里是使用组件化的方式来实现,我百度看,别人用css都可以实现。可以参考一下别人,我在最后面贴上别人的链接。 1.在vue2页面的移动端中…

目前在工作上有一个需求,就是当文本内容过长时,中间显示省略号…,两端正常展示。我这里是使用组件化的方式来实现,我百度看,别人用css都可以实现。可以参考一下别人,我在最后面贴上别人的链接。
1.在vue2页面的移动端中使用;
2.在uni-app开发的微信小程序中使用;

1.用在vue页面:

代码:

<template><div ref="truncatedText" class="text">{{ truncatedText }}</div></template><script>export default {props: {text: String,},data() {return {actualWidth: 0};},computed: {truncatedText() {if (!this.actualWidth) {return this.text;}// 这里是我后面发现有点Bug加的,本意就是当文字的长度小于我们的宽度的时候,就全部展示文字let textWidth2 = this.getTextWidth(testText);if(textWidth2  < his.actualWidth ) return this.text// 这里结束const ellipsis = '...';let start = 0;let end = this.text.length;let middle = Math.floor((start + end) / 2);while (start < middle) {const testText = this.text.slice(0, middle) + ellipsis + this.text.slice(-middle);const testWidth = this.getTextWidth(testText);if (testWidth > this.actualWidth) {end = middle;} else {start = middle;}middle = Math.floor((start + end) / 2);if (middle === start || middle === end) {break;}}return this.text.slice(0, middle) + ellipsis + this.text.slice(-middle);}},mounted() {this.$nextTick(() => {this.actualWidth = this.$refs.truncatedText.offsetWidth;});},methods: {getTextWidth(text) {const canvas = document.createElement('canvas');const context = canvas.getContext('2d');context.font = getComputedStyle(this.$refs.truncatedText).font;return context.measureText(text).width;}}};</script><style scoped>.text {white-space: nowrap;overflow: hidden;}</style>

使用

<truncatedText :text="longText" />

2.用在uni-app上(我这里是用uni-app开发微信小程序)

代码:

<template><div ref="truncatedText" class="text">{{ truncatedText }}</div></template><script>export default {props: {text: String,},data() {return {actualWidth: 0};},computed: {truncatedText() {if (!this.actualWidth) {return this.text;}const fullWidth = this.getTextWidth(this.text);if(fullWidth <= this.actualWidth) return this.textconst ellipsis = '......';let start = 0;let end = this.text.length;let middle = Math.floor((start + end) / 2);if(this.actualWidth < end) {return this.text}while (start < middle) {const testText = this.text.slice(0, middle) + ellipsis + this.text.slice(-middle);const testWidth = this.getTextWidth(testText);if (testWidth > this.actualWidth) {end = middle;} else {start = middle;}middle = Math.floor((start + end) / 2);if (middle === start || middle === end) {break;}}return this.text.slice(0, middle) + ellipsis + this.text.slice(-middle);}},mounted() {this.getActualWidth();},methods: {getActualWidth() {const query = uni.createSelectorQuery().in(this);query.select('.text').boundingClientRect(rect => {this.actualWidth = rect.width;}).exec();},getTextWidth(text) {const context = uni.createCanvasContext('measureCanvas', this);context.setFontSize(14);return context.measureText(text).width;}}};</script><style scoped>.text {white-space: nowrap;overflow: hidden;text-align: justify;}</style>

使用:有点小区别
在样式上有点改动

<template><view class="index"><uni-card title="基础卡片" sub-title="副标题" extra="额外信息" thumbnail="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png"><text>这是一个带头像和双标题的基础卡片,此示例展示了一个完整的卡片。</text></uni-card><view><MiddleEllipsis :text="longText" /></view><view class="box"><view style="text-align: justify;"><truncatedText :text="longText" /></view><view class="box-two">测试数据</view></view></view>
</template><script>
import MiddleEllipsis from '../../components/MiddleEllipsis/MiddleEllipsis.vue';
import truncatedText from '../../components/truncatedText/truncatedText.vue'export default {components: { MiddleEllipsis,truncatedText },data() {return {longText: '这是一个需要中间省略的长文本示例,当容器宽度不足时显示省略号当容器宽度不足时显示省略号'};}
};
</script>
<style scoped>.box {display: flex;align-items: center;padding: 10px;
}.box > view:first-child {flex: 1;min-width: 0; /* 关键:允许文本容器压缩 */
}.box-two {flex-shrink: 0; max-width: 100px;margin-left: 5px;
}
</style>

别人使用js或css实现的,用了好几种方法,可以参考一下:
稀土掘金的资源
https://juejin.cn/post/7329967013923962895?searchId=20250412072930F6FA31D13CD50B9A187D#heading-2

点击蓝色的超链接也可以

http://www.dtcms.com/a/607802.html

相关文章:

  • html静态网站下载专门做处理货的网站
  • 我想自己做的知道网站什么网站做软文
  • 济南建设银行公积金网站seo工程师是什么职业
  • 百度广告投放技巧网站外推和优化
  • ps制作网站过程wordpress更改了数据库密码错误
  • 网站方案组成要素搭建一个小程序需要多少钱
  • 大同网站建设优化推广网站建设公司宣传文案
  • 济南网站微信网站建设平台卜先明
  • 【Android 组件】 实现数据类的 Parcelable 序列化
  • 传媒公司制作网站公司网站备案网址
  • 淮南网络建站公司关键词优化seo优化
  • 电商思维做招聘网站福州自助建站软件
  • 建设网站上海市孝感网站建设专家
  • 建设通官方网站下载e航做网站数据需求分析
  • 制作公司网站用阿里云苗木网站开发需求
  • 深圳高端网站制作公司品牌网站解决方案
  • 物流商 网站建设方案提供常州网站建设
  • 网站搭建三部曲是什么?怎么做辅助发卡网站
  • 重庆建设技术发展中心网站新钥匙建站
  • 优才网站建设广州竞价外包
  • 网站如何做实名验证wordpress 微信二维码登录
  • 个人网站炫酷主页html湖州网站建设公司
  • 佳木斯市郊区建设局网站有专门做网站的公司
  • 双城网站建设公司wordpress song
  • 怎么选择优秀的网站建设公司主机服务器网站 怎么做
  • 高端it网站建设如何修改网站联系人
  • 重庆专业网站搭建扫描网站特征dede
  • 林壑地板北京网站建设wordpress网站弹窗插件
  • 天猫网站做链接怎么做淘客推广是什么
  • OpenSCAD的BOSL库