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

Summary of Vue component basics

Component Basics 1 Component Reuse Components are...

Detailed explanation of MySQL custom functions and stored procedures

Preface This article mainly introduces the releva...

How to use dynamic parameters and calculated properties in Vue

1. Dynamic parameters Starting from 2.6.0, you ca...

Tips for optimizing MySQL SQL statements

When faced with a SQL statement that is not optim...

Configure nginx to redirect to the system maintenance page

Last weekend, a brother project was preparing to ...

Detailed explanation of CocosCreator MVC architecture

Overview This article will introduce the MVC arch...

A brief discussion on how to write beautiful conditional expressions in JS

Table of contents Multiple conditional statements...

XHTML tags have a closing tag

<br />Original link: http://www.dudo.org/art...

Design Association: Why did you look in the wrong place?

I took the bus to work a few days ago. Based on m...

Correct use of MySQL partition tables

Overview of MySQL Partitioned Tables We often enc...

How to open a page in an iframe

Solution: Just set the link's target attribute...

The difference and introduction of ARGB, RGB and RGBA

ARGB is a color mode, which is the RGB color mode...

Getting Started with CSS3 Animation in 10 Minutes

Introduction Animation allows you to easily imple...

Detailed explanation of the use of shared memory in nginx

In the nginx process model, tasks such as traffic...