Detailed explanation of application scenarios of filters in Vue

Detailed explanation of application scenarios of filters in Vue

filter is generally used to filter certain values. For example, if my field is empty, but I want to display “–” on the front end, I can use it.

Recently, I encountered a requirement to set permissions for certain fields to display in other forms, such as displaying the amount that needs to be hidden as "***".

1. Get the amount authority

2. Filter the fields that meet the conditions through filter

3. Return the hidden style

Look at the code:

//For the rest, just look at what I marked. //scope.row gets the current row <template slot-scope="scope">
            <template v-if="item.formType == 'label'">
              <el-button
                v-if="item.link!=undefined"
                type="text" size="small" @click="handleColumnClick(item.link,scope.row)">
                //filter is not generally used for filtering|
                //showLabelValue is not written out //The filter corresponding to one parameter of the method has two parameters //The first one is the value returned by the previous column //The N-1th one is the value you want to pass {{ scope.row | showLabelValue(item) | canViewAmount(canViewAmount,xtType,item) }}
              </el-button>
              <template v-else>
                {{ scope.row | showLabelValue(item) | canViewAmount(canViewAmount,xtType,item) }}
              </template>
            </template>
</template>
export default {
 filters:
 //row is the data returned by scope.rowshowLabelValue(row,item){
 return 'value'
 }
 //value, canView permission, xtType which page, item list data //If showLabelValue returns value, the corresponding canViewAmount parameter value is 'value'
    canViewAmount(value, canView, xtType, item) {
    //If the conditions are met, "***" will be displayed (just display), and the content saved to the database is still the original list if (!canView && xtType == 'salesOrder') {
        if (item.field == 'priceNoTax' || item.field == 'amountNoTax' || item.field == 'price' || item.field == 'amount') {
          return '***'
        }
      }
      if (!canView && xtType == 'project') {
        if (item.field == 'amount' || item.field == 'amountNoTax') {
          return '***'
        }
      }
      return value
    }
  },

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • How to use filters in VUE
  • Detailed explanation of the problem of Vue filters and directives accessing this
  • The problem of this being undefined when using filters in Vue
  • Solve the problem that vue filters cannot get this object
  • Detailed explanation of Vue's data and event binding and filter filters
  • How to use vue filter
  • Summary of four usages of Vue filter

<<:  The problem of jquery.form.js denying access in IE and the input upload button must be actively clicked

>>:  Detailed explanation of the use of IF(), IFNULL(), NULLIF(), and ISNULL() functions in MySQL

Recommend

Python MySQL database table modification and query

Python connects to MySQL to modify and query data...

4 ways to implement routing transition effects in Vue

Vue router transitions are a quick and easy way t...

About the problems of congruence and inequality, equality and inequality in JS

Table of contents Congruent and Incongruent congr...

JavaScript to achieve a simple carousel effect

What is a carousel? Carousel: In a module or wind...

Detailed introduction to the MySQL installation tutorial under Windows

Table of contents 1. Some concepts you need to un...

Small paging design

Let our users choose whether to move forward or ba...

How to make JavaScript sleep or wait

Table of contents Overview Checking setTimeout() ...

CentOS 8 Installation Guide for Zabbix 4.4

Zabbix server environment platform ZABBIX version...

Install CentOS system based on WindowsX Hyper-V

At present, most people who use Linux either use ...

NestJs uses Mongoose to operate MongoDB

I recently started learning the NestJs framework....

Complete steps to implement face recognition login in Ubuntu

1. Install Howdy: howdy project address sudo add-...

Detailed installation process of mysql5.7.21 under win10

This article shares the installation of MySQL 5.7...

MySQL 5.7.18 zip version installation tutorial

The mysql 5.7.18 zip version of MySQL is not like...