# 介绍

# 平台差异说明

App(vue) App(nvue) H5 小程序

此js函数方法,为uview-plus框架提供的一部分功能,它的实现,需要通过js调用,而不是组件的形式,调用方法如下:

  • 如果是在js中,需要通过import形式调用,如调用去除空格的trim方法:
import { trim } from '@/uni_modules/uview-plus';
import { onLoad } from '@dcloudio/uni-app';

onLoad(() => {
  console.log(trim(' abc ')); // 去除两端空格
});
import { trim } from '@/uni_modules/uview-plus';

export default {
  onLoad() {
    console.log(trim(' abc ')); // 去除两端空格
  }
}

  • 如果是在元素中,需挂载methods,如:
<template>
  <view>
    去除所有空格:{{trim(str, 'all')}}
  </view>
</template>

<script setup>
import { trim } from '@/uni_modules/uview-plus';
import { ref } from 'vue';

const str = ref('a  b c ');
</script>
<template>
  <view>
    去除所有空格:{{trim(str, 'all')}}
  </view>
</template>

<script>
import { trim } from '@/uni_modules/uview-plus';
export default {
  data() {
    return {
      str: 'a  b c '
    }
  },
  methods: {
    trim
  }
}
</script>