vue.js中的三元表達式


下面是自己用到的場景

            <el-link
              type="primary"
              :style="{
                'margin-left': '10px',
                'border-bottom': '1px solid',
                color: scope.row.title == '' ? 'lightgrey' : 'DodgerBlue',
              }"
              :underline="true"
              @click="handleEdit(scope.row._id)"
              >{{
                scope.row.title == '' ? '標題為空' : scope.row.title
              }}</el-link`

            <el-input
              v-model="editForm.title"
              :maxlength="
                'maxlength' in editTemplate.title
                  ? editTemplate.title.maxlength
                  : false
              "
              show-word-limit
              clearable
            ></el-input>
 <span v-bind:style="{'display':config.isHaveSearch ? 'block':'none'}" >搜索</span>

補充:當設置maxlength為false時,表示沒有限制。

變量條件真假

[] >>true
 >>false
{} >>true
0 >>false
null >>false
undefined >>false
if(a && a.b) => 當a未null/undefined時,可以避免以下錯誤
Cannot read property 'b' of null
Cannot read property 'b' of undefined

https://cloud.tencent.com/developer/article/1743491


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM