ComTextArea.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="comArea" :style="{'display':slide?'block':'none'}">
  3. <textarea @input="changeVal"
  4. :style="{width:width,height:height}"
  5. v-model="txt"
  6. placeholder="请输入"
  7. @focus="focus"
  8. @blur="blur"></textarea>
  9. </div>
  10. </template>
  11. <script type="text/javascript">
  12. import { isIos } from '@utils/tools';
  13. import $ from 'jquery'
  14. export default {
  15. name:'ComTextArea',
  16. props: {
  17. width: {
  18. default: '100%',
  19. type: String
  20. },
  21. height: {
  22. default: '2rem',
  23. type: String
  24. },
  25. item:{
  26. type:Object,
  27. require: true
  28. },
  29. slide:{
  30. default:false,
  31. type:Boolean
  32. }
  33. },
  34. data() {
  35. return {
  36. txt:this.item.value || '' //回读用
  37. // txt:''
  38. }
  39. },
  40. methods:{
  41. changeVal(){
  42. // $(".btscroll").css({'position':'fixed'})
  43. this.$emit('changeAreaVal',this.txt)
  44. const newData = Object.assign({},this.item,{value:this.txt,valueP:this.txt});
  45. this.$emit("updata",newData);
  46. },
  47. blur(){
  48. document.activeElement.scrollIntoViewIfNeeded(true);
  49. $(".foot").css({'display':'block'})
  50. setTimeout(()=>{
  51. document.activeElement.scrollIntoViewIfNeeded(true);
  52. },300)
  53. },
  54. focus(){
  55. if(isIos()){
  56. // $(".btscroll").css({'position':'absolute'})
  57. $(".foot").css({'display':'none'})
  58. }
  59. }
  60. },
  61. watch:{
  62. item:{//清空时更新数据
  63. handler(newVal,oldVal){
  64. this.txt = newVal.value;
  65. },
  66. deep:true
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="less" scoped>
  72. @import '../less/base.less';
  73. .comArea {
  74. .bgques;
  75. textarea {
  76. color: #4F50FF;
  77. resize: none;
  78. box-shadow: none;
  79. font-size: 0.3rem;
  80. box-sizing: border-box;
  81. border: 1px solid #DFE0E4;
  82. border-radius: .08rem /* 8/100 */;
  83. -webkit-appearance: none;
  84. padding: .16rem /* 16/100 */ .3rem /* 30/100 */;
  85. background-color: transparent;
  86. }
  87. }
  88. </style>