最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - Kendo UI render Vue JS variable within a html input element - Stack Overflow

programmeradmin0浏览0评论

I using Kendo UI. I am trying to render a ternary operator within a html input checkbox.

The below create an error. How do i escape the values.

 <input type="checkbox" class="checkbox"  "\# (myVar)  ? ('checked') : '' #\">

My view script:

<script type="text/javascript">

    var app = new Vue({

      el: '#app',

      data: {

        myVar:true

      }

    })

</script>

I using Kendo UI. I am trying to render a ternary operator within a html input checkbox.

The below create an error. How do i escape the values.

 <input type="checkbox" class="checkbox"  "\# (myVar)  ? ('checked') : '' #\">

My view script:

<script type="text/javascript">

    var app = new Vue({

      el: '#app',

      data: {

        myVar:true

      }

    })

</script>
Share Improve this question asked Feb 6 at 17:48 templetemple 231 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

As shown in the docs, you can write something like this

<input type="checkbox" class="checkbox" :class="{ 'checked': myVar }">

And if myVar is truthy, it will then generate a checkbox checked class.


But you probably meant to have the attribute checked here?

Hence this might be more fitting as a general example

<script setup>
import { ref } from 'vue'

const myVar = ref(true)
</script>

<template>
  <p>Current value of 'myVar' is {{ myVar }}</p>

  <input type="checkbox" id="checkbox" v-model="myVar" />
  <label for="checkbox">{{ myVar }}</label>

  <br />
  <br />
  <input type="checkbox" class="checkbox" :class="{ 'checked': myVar }">
</template>

<style scoped>
.checked {
  margin: 2rem;
}
</style>

Here is a playground.
And here are the related docs for that specific binding.

发布评论

评论列表(0)

  1. 暂无评论