javascript - Vue.js + Element UI - How to change value el-switch - Stack Overflow

I have data from server. The response data is integer 1 or 0, In view i use element ui el-switch, it se

I have data from server. The response data is integer 1 or 0, In view i use element ui el-switch, it set value with boolean true or false.

Is there anyway can help me? It's my code

<div class="row">
          <el-col :span="9">
            <el-form-item>
              <p style="margin-top: 15px">sale in POS</p>
            </el-form-item>
          </el-col>
          <el-col :span="15" class="switch-varian">
            <el-switch inactive-color="#ff4949" v-model="product.pos_hidden" @change="valuePOS"></el-switch>
            <div v-if="product.pos_hidden === 1">
              <p class="desc-switch">
                <strong>Yes</strong>
              </p>
              <p class="desc-switch">This Product Sale in POS</p>
            </div>
            <div v-else>
              <p class="desc-switch">
                <strong>No</strong>
              </p>
              <p>This Product Not Sale in POS</p>
            </div>
          </el-col>
        </div>

methods: {
loadData() {
  this.loading = true
  let headers = {
    Authorization: 'Bearer ' + window.accessToken
  }

  axios({
    method: 'GET',
    url: BASE_API + 'product/' + this.$route.params.id,
    params: this.params,
    headers: headers
  })
    .then(response => {
      this.product = response.data.data
      this.loading = false
    })
    .catch(error => {
      console.log(error)
      this.loading = true
      this.$notify({
        title: 'Error: ' + error,
        type: 'warning',
        message: 'Error: ' + error
      })
    })
},
valuePOS(val) {
  if (val === true) {
    fooBar | 1
  } else {
    fooBar | 0
  }
}

Expected : I want to change value from response to boolean value. And then i'll edit that value and send request to server with new value as an integer value.

I have data from server. The response data is integer 1 or 0, In view i use element ui el-switch, it set value with boolean true or false.

Is there anyway can help me? It's my code

<div class="row">
          <el-col :span="9">
            <el-form-item>
              <p style="margin-top: 15px">sale in POS</p>
            </el-form-item>
          </el-col>
          <el-col :span="15" class="switch-varian">
            <el-switch inactive-color="#ff4949" v-model="product.pos_hidden" @change="valuePOS"></el-switch>
            <div v-if="product.pos_hidden === 1">
              <p class="desc-switch">
                <strong>Yes</strong>
              </p>
              <p class="desc-switch">This Product Sale in POS</p>
            </div>
            <div v-else>
              <p class="desc-switch">
                <strong>No</strong>
              </p>
              <p>This Product Not Sale in POS</p>
            </div>
          </el-col>
        </div>

methods: {
loadData() {
  this.loading = true
  let headers = {
    Authorization: 'Bearer ' + window.accessToken
  }

  axios({
    method: 'GET',
    url: BASE_API + 'product/' + this.$route.params.id,
    params: this.params,
    headers: headers
  })
    .then(response => {
      this.product = response.data.data
      this.loading = false
    })
    .catch(error => {
      console.log(error)
      this.loading = true
      this.$notify({
        title: 'Error: ' + error,
        type: 'warning',
        message: 'Error: ' + error
      })
    })
},
valuePOS(val) {
  if (val === true) {
    fooBar | 1
  } else {
    fooBar | 0
  }
}

Expected : I want to change value from response to boolean value. And then i'll edit that value and send request to server with new value as an integer value.

Share Improve this question asked May 22, 2018 at 4:44 dede.brahmadede.brahma 3297 gold badges13 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

You can use active-value and inactive-value. Document

  <el-switch
    v-model="product.pos_hidden"
    :active-value="1"
    :inactive-value="0">
  </el-switch>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745418403a4626857.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信