tm-position.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="tm-position relative ">
  3. <view class="tm-position-content">
  4. <slot name="default"></slot>
  5. </view>
  6. <view :style="{
  7. top:position_s.top==true?0:'null'+'px',
  8. bottom:position_s.bottom==true?0:'null'+'px',
  9. transform:`translateY(${offset[1]}px) translateX(${offset[0]}px)`,
  10. }" class="tm-position-body absolute" :class="[
  11. position_s.left?'flex-start':'',
  12. position_s.right?'flex-end':'',
  13. ]" >
  14. <slot name="position"></slot>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. /**
  20. * 定位组件
  21. * @property {Object} position = [] 位置{top:false,left:false,right:false,bottom:false}
  22. * @property {Array} offset = [] 默认:[0,0],偏移x,y
  23. */
  24. export default {
  25. name:"tm-position",
  26. props:{
  27. position:{
  28. type:Object,
  29. default:()=>{
  30. return {};
  31. }
  32. },
  33. offset:{
  34. type:Array,
  35. default:()=>{
  36. return [0,0];
  37. }
  38. },
  39. },
  40. computed:{
  41. position_s:function(){
  42. let p = {
  43. top:false,
  44. left:false,
  45. right:false,
  46. bottom:false
  47. };
  48. return {...p,...this.position}
  49. },
  50. },
  51. data() {
  52. return {
  53. height:0
  54. };
  55. },
  56. async mounted() {
  57. // this.$nextTick(async function(){
  58. // let syinfo = await this.$Querey('.tm-position-content',this).catch(e=>{})
  59. // console.log(syinfo);
  60. // this.height = syinfo[0].height;
  61. // })
  62. }
  63. }
  64. </script>
  65. <style lang="less">
  66. .tm-position{
  67. .tm-position-body{
  68. width: 100%;
  69. }
  70. .tm-position-content{
  71. }
  72. }
  73. </style>