c-tip


提示

示例

  1. <template>
  2. <page title="c-tip演示">
  3. <view class="tip-eg">
  4. <c-tip show="{{showtip1}}" direction="top" c-bind:close="closeTip1" style="position:absolute;top:0;left:300cpx;">
  5. <text style="font-size: 24cpx;color: #fff">Tip</text>
  6. </c-tip>
  7. <text class="tip-btn" c-bind:tap="showTip1">Show tip</text>
  8. </view>
  9. <view class="tip-eg">
  10. <c-tip show="{{showtip2}}" direction="{{direction}}" c-bind:close="closeTip2" style="{{tipStyle}}">
  11. <text style="font-size: 24cpx;color: #fff">Awesome!</text>
  12. </c-tip>
  13. <text class="tip-btn" c-bind:tap="showTip2">chameleon-ui</text>
  14. </view>
  15. <button class="btn" c-bind:onclick="showTip2Top" text="top"></button>
  16. <button class="btn" c-bind:onclick="showTip2Bottom" text="bottom"></button>
  17. <button class="btn" c-bind:onclick="showTip2Left" text="left"></button>
  18. <button class="btn" c-bind:onclick="showTip2Right" text="right"></button>
  19. </page>
  20. </template>
  21. <script>
  22. class CTip {
  23. data = {
  24. showtip1: false,
  25. showtip2: false,
  26. direction: "top"
  27. }
  28. computed = {
  29. tipStyle() {
  30. let style;
  31. switch (this.direction) {
  32. case "top":
  33. style =
  34. "position:absolute;top:0;left: 260cpx;";
  35. break;
  36. case "bottom":
  37. style =
  38. "position:absolute;top:164cpx;left: 260cpx;";
  39. break;
  40. case "left":
  41. style = "position:absolute;left:20cpx;top:93cpx;";
  42. break;
  43. case "right":
  44. style = "position:absolute;left:480cpx;top:93cpx;";
  45. break;
  46. }
  47. return this.$cmlStyle(style);
  48. }
  49. }
  50. methods = {
  51. closeTip1(){
  52. this.showtip1=false;
  53. },
  54. showTip1(){
  55. this.showtip1=true;
  56. },
  57. closeTip2(){
  58. this.showtip2 = false;
  59. },
  60. showTip2(){
  61. this.direction="top";
  62. this.showtip2 = true;
  63. },
  64. showTip2Top(){
  65. this.direction="top";
  66. this.showtip2 = true;
  67. },
  68. showTip2Bottom(){
  69. this.direction="bottom";
  70. this.showtip2= true;
  71. },
  72. showTip2Left(){
  73. this.direction="left";
  74. this.showtip2=true;
  75. },
  76. showTip2Right(){
  77. this.direction="right";
  78. this.showtip2=true;
  79. }
  80. }
  81. }
  82. export default new CTip();
  83. </script>
  84. <style scoped>
  85. .container {
  86. display: flex;
  87. flex-direction: column;
  88. }
  89. .tip-eg {
  90. width: 750cpx;
  91. align-self: center;
  92. padding: 100cpx 0;
  93. position: relative;
  94. display: flex;
  95. flex-direction: column;
  96. }
  97. .tip-btn {
  98. padding: 9cpx 10cpx;
  99. border: 1px solid #fc9153;
  100. border-radius: 4cpx;
  101. font-size: 24cpx;
  102. color: #fc9153;
  103. align-self: center;
  104. }
  105. .btn {
  106. margin-top: 20cpx;
  107. align-self: center;
  108. }
  109. </style>
  110. <script cml-type="json">
  111. {
  112. "base": {
  113. "usingComponents": {
  114. "c-tip": "cml-ui/components/c-tip/c-tip"
  115. }
  116. }
  117. }
  118. </script>