Skip to content
Advertisement

How can I formatt a value in v-for inside a el-option in element ui

I need formatt to decimal value the value in label(item.value) inside a v-for.

Here is my code:

<el-form-item :label="label" :required="required" prop="Jan">
      <el-select v-model="Jan" clearable filterable placeholder="Selecione" :multiple="multiple" :disabled="disabled" :loading="loading" @change="onChange">
        <el-option
          v-for="item in orcindex"
          :key="item.id"
          :label="item.name + ' - ' + item.value + '%'"
          :value="item.id"
        />
      </el-select>
    </el-form-item>

I already have a function to formatt:

import { numberFormat } from ‘@/utils/cells-format’

 methods: {
    cellValueRenderer(cellValue) {
      var value = numberFormat(cellValue, 'decimal')
      return value
    }
 }

So how can I use this function to formatt the value in v-for? (Im new in vuejs)

Advertisement

Answer

You can directly use the function.

<el-option
      v-for="item in orcindex"
      :key="item.id"
      :label="item.name + ' - ' + cellValueRenderer(item.value) + '%'"
      :value="item.id"
    />
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement