text-props.uvue 4.8 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1
<template>
H
hdx 已提交
2
  <scroll-view class="page-scroll-view">
DCloud-WZF's avatar
DCloud-WZF 已提交
3 4 5 6 7
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
      <view class="uni-title">
        <text class="uni-title-text">text相关属性示例</text>
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
8

DCloud-WZF's avatar
DCloud-WZF 已提交
9 10 11 12 13 14
      <view class="uni-title">
        <text class="uni-subtitle-text">根据宽度自动折行</text>
      </view>
      <view class="text-box">
        <text>{{ multiLineText }}</text>
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
15

DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18 19 20 21 22 23
      <view class="uni-title">
        <text class="uni-subtitle-text">\\n换行</text>
      </view>
      <view class="text-box">
        <text>\n 换行</text>
        <text>\\n 换行</text>
        <text>\\\n 换行</text>
        <text>\n 换行 \\n 换行 \\\n 换行 \\\\n 换行 \\\\\n 换行</text>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
24
        <text space="nbsp">HBuilderX,轻巧、极速,极客编辑器;\nuni-app x,终极跨平台方案;</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
25
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
26

DCloud-WZF's avatar
DCloud-WZF 已提交
27 28 29
      <view class="uni-title">
        <text class="uni-subtitle-text">截断(clip)</text>
      </view>
30
      <view class="text-box">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
31
        <text class="uni-flex-item" style="text-overflow: clip;white-space: nowrap;">{{
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33 34
          multiLineText
        }}</text>
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
35

DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38
      <view class="uni-title">
        <text class="uni-subtitle-text">截断(ellipsis)</text>
      </view>
39
      <view class="text-box">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
40
        <text class="uni-flex-item" style="text-overflow: ellipsis;white-space: nowrap;">{{
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42 43
          multiLineText
        }}</text>
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
44

DCloud-WZF's avatar
DCloud-WZF 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
      <view class="uni-title">
        <text class="uni-subtitle-text">selectable</text>
      </view>
      <view class="text-box">
        <text :selectable="true">{{ singleLineText }}</text>
      </view>

      <view class="uni-title">
        <text class="uni-subtitle-text">space</text>
        <text class="uni-subtitle-text">依次为nbsp ensp emsp效果</text>
      </view>
      <view class="text-box">
        <text space="nbsp">{{ singleLineText }}</text>
        <text space="ensp">{{ singleLineText }}</text>
        <text space="emsp">{{ singleLineText }}</text>
      </view>

      <view class="uni-title">
        <text class="uni-subtitle-text">decode</text>
        <text class="uni-subtitle-text"
          >依次为lt gt amp apos nbsp ensp emsp效果</text
        >
      </view>
      <view class="text-box">
        <text :decode="true">&lt; &gt; &amp; &apos;</text>
        <text :decode="true">uni-app&nbsp;x,终极跨平台方案</text>
        <text :decode="true">uni-app&ensp;x,终极跨平台方案</text>
        <text :decode="true">uni-app&emsp;x,终极跨平台方案</text>
      </view>

      <view class="uni-title">
        <text class="uni-subtitle-text">嵌套</text>
      </view>
      <view class="text-box">
        <text
          >一级节点黑色
81
          <text id="text-nested" ref="text-nested" style="color: red;background-color: yellow;"
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
82
            >二级节点红色且背景色黄色
DCloud-WZF's avatar
DCloud-WZF 已提交
83 84 85 86 87
            <text>三级节点不继承二级的颜色</text>
          </text>
          <text style="font-size: 50px">二级节点大字体</text>
        </text>
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
88 89 90 91 92 93 94 95 96 97 98

      <view class="uni-title">
        <text class="uni-subtitle-text">padding</text>
      </view>
      <view class="text-box">
        <text class="text-padding">hello uni-app x</text>
        <text class="text-padding" style="width: 200px;">hello uni-app x</text>
        <text class="text-padding" style="height: 100px;">hello uni-app x</text>
        <text class="text-padding" style="width: 200px;height: 100px;">hello uni-app x</text>
      </view>

99
      <view class="uni-row" v-if="autoTest">
100 101
        <text id="empty-text"></text>
      </view>
102 103 104
      <view class="uni-row" v-if="autoTest">
        <text id="empty-text2" ref="empty-text2">test</text>
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
105 106
    </view>
  </scroll-view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
107 108 109
</template>

<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111 112 113 114 115 116
export default {
  data() {
    return {
      title: 'text-props',
      multiLineText:
        'HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言;HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言',
      singleLineText: 'uni-app x,终极跨平台方案',
117 118
      // 自动化测试
      autoTest: false
DCloud-WZF's avatar
DCloud-WZF 已提交
119 120
    }
  },
121 122 123
  methods: {
    // 自动化测试
    setTextNested() {
124 125 126 127
      (this.$refs["text-nested"] as UniElement).setAttribute("value", "二级节点文字红色且背景色黄色");
    },
    setTextEmpty() {
      (this.$refs["empty-text2"] as UniElement).setAttribute("value", "");
128 129
    }
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
130
}
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
131 132 133
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
134
.text-box {
H
hdx 已提交
135 136
  margin-bottom: 20px;
  padding: 20px 0;
DCloud-WZF's avatar
DCloud-WZF 已提交
137 138 139 140
  background-color: #ffffff;
  justify-content: center;
  align-items: center;
}
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
141

DCloud-WZF's avatar
DCloud-WZF 已提交
142
.text {
H
hdx 已提交
143
  font-size: 15px;
DCloud-WZF's avatar
DCloud-WZF 已提交
144
  color: #353535;
H
hdx 已提交
145
  line-height: 27px;
DCloud-WZF's avatar
DCloud-WZF 已提交
146 147
  text-align: center;
}
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
148 149 150 151 152 153 154

.text-padding {
  margin-top: 5px;
  padding: 20px;
  border: 1px solid red;
  text-align: center;
}
DCloud-WZF's avatar
DCloud-WZF 已提交
155
</style>