可以通过给第一个text组件设置postion:absolute,第二个text组件设置文本首行缩进属性text-indent,预留出对应的宽度,示例代码如下: <template>
<div style="flex-direction: column;">
<div>
<text id="11" style="background-color: #E34547;color:#FFFFFF;position: absolute;border-radius: 10px;margin-left: 5px">{{value}}</text>
<text style="text-indent:{{kuan}};">Detailed description of a product.</text>
</div>
</div>
</template>
<style>
</style>
<script>
module.exports = {
data: {
kuan: '',
value: '精选'
},
onInit() {
this.$page.setTitleBar({ text: '' })
this.value=" Tag "
},
onShow() {
'// Do something when show.'
var that = this
this.$element('11').getBoundingClientRect({
success: function (data) {
that.kuan = data.width + 20 + 'px'
console.log("message", that.kuan);
console.log('getBoundingClientRect succeeded, result data =' + JSON.stringify(data));
console.log('getBoundingClientRect succeeded, result data =' + data.width,'hou',that.kuan);
},
});
},
}
</script> 运行效果图如下所示:
|