有問題好吧,我有一個問題,雖然是一個奇怪的,我已經全部結束,似乎無法找到答案。與VueJS類綁定問題,使用vuejs v2.0 +引導v3.3.7
我們被分配創建一個Vue.js的購物車,我已經完成了,我自己開始了這個項目,並想看看我能用vuejs做些什麼。問題發生在頁面加載後,訪問「管理」面板,我創建了一個警報管理器,使用引導程序即時創建警報,稍後在此處發佈代碼。問題是我想擁有複選框值並使用該選項輸入正確的警報類別,即「alert alert-success」。
我正在使用綁定,奇怪的是,類的工作類,只有警報危險,並始終如一。我不知道我爲什麼或者我做錯了什麼,需要一雙新的眼睛,也許我們可以讓它工作。下面是我修改後的代碼基於正在破解的代碼創建了一個單獨的html/vuejs頁面...對象正在成功創建,問題出現在輸出到頁面的某處...代碼會扭曲,但您會可能需要鏈接一個活vue副本到它,因爲代碼太多上傳,CDN 2.0.3或更高版本應該工作。
//I have the VueJS file downloaded, and in the root folder... but dont want to upload this file to teh site due to the shear size. I am useing VueJS v2.1.2 i think, but it is definitly between 2.0.3 and 2.1.2
//this is the code only pertaining to the part that is breaking...
myAPP = new Vue({
el: '#testapp',
data:{
alerts: [],
newAlertObj: {
alertTitle:'',
alertMsg:'',
alerttypeSuccess:false,
alerttypeInfo:false,
alerttypeWarn:false,
alerttypeDanger:false,
alerttypeDismiss:false,
alerttypeAnimate:false
},
alertadd:false,
//radio options for alert add [[No longer used as the object is being created as far as i can tell correctly]]//
/*
isSuccess:false,
isInfo:false,
isWarn:false,
isDanger:false,
//for check boxes//
isAnimated:false,
isDismissable:false*/
},
methods:{
addAlertObj:function(){
console.log(this.alerts.push(this.newAlertObj))
//debug
console.log(this.newAlertObj.alerttypeSuccess)
console.log(this.newAlertObj.alerttypeInfo)
console.log(this.newAlertObj.alerttypeWarn)
console.log(this.newAlertObj.alerttypeDanger)
console.log(this.newAlertObj.alerttypeDismiss)
console.log(this.newAlertObj.alerttypeAnimate)
this.newAlertObj={alertTitle:'',alertMsg:'',alerttypeSuccess:false,alerttypeInfo:false,alerttypeWarn:false,alerttypeDanger:false,alerttypeDismiss:false,alerttypeAnimate:false}
},
togglealertadder: function(){
if (this.alertadd){
this.alertadd=false
this.newAlertObj={alertTitle:'',alertMsg:'',alerttypeSuccess:false,alerttypeInfo:false,alerttypeWarn:false,alerttypeDanger:false,alerttypeDismiss:false,alerttypeAnimate:false}
}else{
this.alertadd=true
}
}
}
});
<! DOCTYPE html>
<html lang="en" charset="utf-8">
<head>
<title>Test App</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> <!--jquery cdn-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="style.css"> <!--site deffinitions and styles-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.4/vue.js"></script>
</head>
<body>
<div class="container">
<div class="container-fluid">
<!-- test of the alert creation elements only goes here -->
<div id="testapp">
<div id="AlertsNMessages">
<!-- Log in state only messages -->
<p class="alert alert-warning"><span style="font-weight:bold;">WARNING! </span> You are logged into ADMIN mode, remember to logout</p>
<div class = "row">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<div class="panel panel-default">
<div class="panel-heading">
<button type="button" class="btn btn-primary btn-block" @click="togglealertadder">Manage Alerts</button>
</div>
<div class="panel-body" v-if="alertadd">
<div class="form-group">
Alert Content:
<input class="form-control" placeholder="Alert Title" v-model="newAlertObj.alertTitle" /><br />
<input class="form-control" placeholder="Alert Text" v-model="newAlertObj.alertMsg" /><br />
Alert Options (Only select ONE option below!):<br />
<input type="checkbox" name="alerttype" v-model="newAlertObj.alerttypeSuccess"/> Sucess Formatting
<input type="checkbox" name="alerttype1" v-model="newAlertObj.alerttypeInfo" /> Info Formatting
<input type="checkbox" name="alerttype2" v-model="newAlertObj.alerttypeWarn" /> Warn Formatting
<input type="checkbox" name="alerttype3" v-model="newAlertObj.alerttypeDanger" /> Danger Formating<br /><br />
Alert Optional Options:<br />
<input type="checkbox" class="" v-model="newAlertObj.alerttypeDismiss" /> Dismissable
<input type="checkbox" class="" v-model="newAlertObj.alerttypeAnimate" /> Animate <br /><br />
<button type="button" class="btn btn-primary" @click="addAlertObj">Create Alert</button>
</div>
{{newAlertObj.alerttypeSuccess}}
{{newAlertObj.alerttypeInfo}}
{{newAlertObj.alerttypeWarn}}
{{newAlertObj.alerttypeDanger}}
<h4>Alerts and Message Administration:</h4>
<div id="testing" v-for="(item,index) in alerts">
<li style="list-style-type:none;">
<button type="button" class="btn btn-danger" @click="alerts.splice(index,1)">×</button>
{{alerts[index].alertTitle}}
{{alerts[index].alertMsg}}
Success:{{alerts[index].alerttypeSuccess}}
Info:{{alerts[index].alerttypeInfo}}
Warn:{{alerts[index].alerttypeWarn}}
Danger:{{alerts[index].alerttypeDanger}}
Animate:{{alerts[index].alerttypeAnimate}}
Dismiss:{{alerts[index].alerttypeDismiss}}
</li><br />
</div>
</div>
</div>
</div>
<div class="col-sm-2"></div>
</div>
<!-- everybody messages -->
<!-- It is here that the opbject gets translated to the page based on the opbject values.-->
<!-- alert is a static class, the :class are the dynamic whih just format the alert apearence... but it shows only text. -->
<div id="everybodymessages" v-for="(item,index) in alerts">
<p class="alert"
:class="{
'alert-sucess':alerts[index].alerttypeSuccess,
'alert-info':alerts[index].alerttypeInfo,
'alert-warning':alerts[index].alerttypeWarn,
'alert-danger':alerts[index].alerttypeDanger
}">
{{alerts[index].alertTitle}} {{alerts[index].alertMsg}}</p>
</div>
</div>
</div>
</div>
</div>
<script src="testapp.js"></script>
</body>
</html>
我一直在做調試與上面的代碼,它似乎停止圍繞DIV ID工作 「everyonemessages」。生成時,代碼應該呈現一個引導消息警報,從複選框中選擇類並綁定到靜態警告類..但所有打印在HTML上的文本是純文本...我一直在盡我所能設法得到它虧本工作,我...我會在一點點編輯更多,但我認爲是很好的現在:
感謝的帖子, 傑西˚F
我不確定我是否理解這個問題......除了成功之外,所有提醒都能正常工作。成功不起作用,因爲你給了它''alert-sucess'類,但它應該是'alert-success'(兩個'c'在'成功') – asemahle
我是個白癡...... - 我不能相信我沒有收到...謝謝...我標記了回答...它的工作,我真的不能用ouy做到 –
沒問題:D很高興能有幫助 – asemahle