<div id="app">
<h4>物件寫法</h4>
<div class="box" v-Bind:class="{'rotate': isTransform,'bg-danger':boxColor}" ></div>
<!-- vbind 可以使用rotate : true or false 再透過@click 去切換 true or false 也可以寫成物件的方式 -->
<p>請為此元素加上動態 className</p>
<hr>
<button class="btn btn-outline-primary" @click="isTransform = !isTransform">選轉物件</button>
 
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle1" v-model="boxColor">
<label class="form-check-label" for="classToggle1">切換色彩</label>
</div>
<hr>
<h5>物件寫法 2</h5>
<div class="box":class="objectClass" ></div>
<!-- objectClass本身就是個物件
objectClass.rotate 為true or false
objectClass.bg-danger 為true or false
-不能當作變數所以要把objectClass.bg-danger 改成objectClass['bg-danger'] -->
<p>請將此範例改為 "物件" 寫法</p>
<hr>
<button class="btn btn-outline-primary" @click="objectClass.rotate=!objectClass.rotate">選轉物件</button>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle2" v-model="objectClass['bg-danger'] ">
<label class="form-check-label" for="classToggle2" >切換色彩</label>
</div>
<hr>
<h4>陣列寫法</h4>
<button class="btn " :class="arrayClass">請操作本元件</button>
<!-- arrayClass 為空陣列
透過v-model 加入class name -->
 
<p>請用陣列呈現此元件 className</p>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle3" v-model="arrayClass" value="btn-outline-primary">
<label class="form-check-label" for="classToggle3">切換樣式</label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle4" v-model="arrayClass" value="active">
<label class="form-check-label" for="classToggle4">啟用元素狀態</label>
</div>
<hr>
<h4>綁定行內樣式</h4>
<p>請用不同方式綁定以下行內樣式</p>
<!-- 加入style的4種方式
{backgroundColor:'red'} 物件
styleObject 變數是物件
styleObject: {
backgroundColor: 'red',
borderWidth: '5px'
},
[{backgroundColor:'red'},{borderWidth:'5px'}] 變數是陣列帶物件
[styleObject,styleObject2] 物件1,物件2 -->
 
<div class="box" :style="{backgroundColor:'red'}"></div>
<div class="box":style ="styleObject"></div>
<div class="box":style ="[{backgroundColor:'red'},{borderWidth:'5px'}]"></div>
<div class="box":style ="[styleObject,styleObject2]"></div>
<hr>
<h5>自動加上 Prefix (每個版本結果不同)</h5>
<div class="box"></div>
</div>
 
<script>
var app = new Vue({
el: '#app',
data: {
isTransform: false,
boxColor: false,
objectClass: {
'rotate': false,
'bg-danger': false,
},
 
// Array 操作
arrayClass: [],
 
// 行內樣式
// 使用駝峰式命名
styleObject: {
backgroundColor: 'red',
borderWidth: '5px'
},
styleObject2: {
boxShadow: '3px 3px 5px rgba(0, 0, 0, 0.16)'
},
styleObject3: {
userSelect: 'none'
}
},
});
</script>
 
<style>
.box {
transition: all .5s;
}
.box.rotate {
transform: rotate(45deg)
}
</style>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()

 
<div id="app">
<h4>物件寫法</h4>
<div class="box" v-Bind:class="{'rotate': isTransform,'bg-danger':boxColor}" ></div>
<!-- vbind 可以使用rotate : true or false 再透過@click 去切換 true or false 也可以寫成物件的方式 -->
<p>請為此元素加上動態 className</p>
<hr>
<button class="btn btn-outline-primary" @click="isTransform = !isTransform">選轉物件</button>
 
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle1" v-model="boxColor">
<label class="form-check-label" for="classToggle1">切換色彩</label>
</div>
<hr>
<h5>物件寫法 2</h5>
<div class="box":class="objectClass" ></div>
<!-- objectClass本身就是個物件
objectClass.rotate 為true or false
objectClass.bg-danger 為true or false
-不能當作變數所以要把objectClass.bg-danger 改成objectClass['bg-danger'] -->
<p>請將此範例改為 "物件" 寫法</p>
<hr>
<button class="btn btn-outline-primary" @click="objectClass.rotate=!objectClass.rotate">選轉物件</button>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle2" v-model="objectClass['bg-danger'] ">
<label class="form-check-label" for="classToggle2" >切換色彩</label>
</div>
<hr>
<h4>陣列寫法</h4>
<button class="btn " :class="arrayClass">請操作本元件</button>
<!-- arrayClass 為空陣列
透過v-model 加入class name -->
 
<p>請用陣列呈現此元件 className</p>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle3" v-model="arrayClass" value="btn-outline-primary">
<label class="form-check-label" for="classToggle3">切換樣式</label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="classToggle4" v-model="arrayClass" value="active">
<label class="form-check-label" for="classToggle4">啟用元素狀態</label>
</div>
<hr>
<h4>綁定行內樣式</h4>
<p>請用不同方式綁定以下行內樣式</p>
<!-- 加入style的4種方式
{backgroundColor:'red'} 物件
styleObject 變數是物件
styleObject: {
backgroundColor: 'red',
borderWidth: '5px'
},
[{backgroundColor:'red'},{borderWidth:'5px'}] 變數是陣列帶物件
[styleObject,styleObject2] 物件1,物件2 -->
 
<div class="box" :style="{backgroundColor:'red'}"></div>
<div class="box":style ="styleObject"></div>
<div class="box":style ="[{backgroundColor:'red'},{borderWidth:'5px'}]"></div>
<div class="box":style ="[styleObject,styleObject2]"></div>
<hr>
<h5>自動加上 Prefix (每個版本結果不同)</h5>
<div class="box"></div>
</div>
 
<script>
var app = new Vue({
el: '#app',
data: {
isTransform: false,
boxColor: false,
objectClass: {
'rotate': false,
'bg-danger': false,
},
 
// Array 操作
arrayClass: [],
 
// 行內樣式
// 使用駝峰式命名
styleObject: {
backgroundColor: 'red',
borderWidth: '5px'
},
styleObject2: {
boxShadow: '3px 3px 5px rgba(0, 0, 0, 0.16)'
},
styleObject3: {
userSelect: 'none'
}
},
});
</script>
 
<style>
.box {
transition: all .5s;
}
.box.rotate {
transform: rotate(45deg)
}
</style>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()



<div id="app">

<div class="input-group mb-3">

<div class="input-group-prepend">

<span class="input-group-text" id="basic-addon1">待辦事項</span>

</div>

<input type="text" class="form-control" v-model="newTodo" placeholder="準備要做的任務" v-on:keyup.enter="addTodo">

<div class="input-group-append">

<button class="btn btn-primary" v-on:click="addTodo" type="button">新增</button>

</div>

</div>

<div class="card text-center">

<div class="card-header">

<ul class="nav nav-tabs card-header-tabs">

<li class="nav-item">

<a class="nav-link" :class="{'active' : visibility == 'all'}" @click="visibility = 'all'" href="#">全部</a>

</li>

<li class="nav-item">

<a class="nav-link " :class="{'active' : visibility == 'active'}" @click="visibility = 'active' " href="#">進行中</a>

</li>

<li class="nav-item">

<a class="nav-link" :class="{'active' : visibility == 'completed'}" @click="visibility = 'completed' " href="#">已完成</a>

</li>

</ul>

</div>

<ul class="list-group list-group-flush text-left">

<li class="list-group-item"

@dblclick="editTodo(item)"

v-for="(item,key) in filteredTodos">

<div class="d-flex"

v-if ="item.id !== cacheTodo.id" >

<div class="form-check">

<input type="checkbox" v-model="item.completed" class="form-check-input" :id="item.id">

<label :class="{'completed' : item.completed} " class="form-check-label" :for="item.id">

{{ item.title }}

</label>

 

 
</div>

<button type="button" class="close ml-auto" aria-label="Close" v-on:click="removeTodo(item.id)">

<span aria-hidden="true">&times;</span>

</button>

</div>

<input type="text" class="form-control"

v-model="cacheTitle"

@keyup.esc="cancelEdit()"

v-if ="item.id == cacheTodo.id"

@keyup.enter="doneEdit(item)"

>

</li>

<!-- <li class="list-group-item">

<input type="text" class="form-control">

</li> -->

</ul>

<div class="card-footer d-flex justify-content-between">

<span>還有 3 筆任務未完成</span>

<a href="#">清除所有任務</a>

</div>

</div>

</div>

 
<script>

 
 

// 按到label 觸發id到input ,觸發input 就會觸發v-model false--->true---> item.completed變成false 就會加上completed 的class

var app = new Vue({

el: '#app',

data: {

newTodo: '',

todos: [{

id: '123', title: '你好', completed: false,

},

],

cacheTodo:{},

cachetitle:'',

visibility: 'all'

 
},

methods: {

addTodo: function () {

var value = this.newTodo.trim(); //空格會被刪掉

var timestamp = Math.floor(Date.now())

if (!value) { //value為空值時就不能執行

return;

}

this.todos.push({

id: timestamp,

title: value,

completed: false,

})

this.newTodo = '';

},

removeTodo: function (key) {

for (var i = 0; i < this.todos.length; i++) {

 
if (this.todos[i].id == key) {

this.todos.splice(i, 1)

}//當刪除那筆key的timestamp = todos裡的timestamp

}//就刪除當下的index

},

editTodo: function (item) {

this.cacheTodo =item;

this.cacheTitle=item.title

},

cancelEdit:function(){

this.cacheTodo='';

 
},

doneEdit: function(item){

console.log(item.title)

item.title= this.cacheTitle;

console.log(item.title)

this.cacheTitle ='';

console.log(item.title)

this.cacheTodo={};

console.log(item.title)

}

},

 

computed: {

filteredTodos: function () {

if (this.visibility == 'all') {

return this.todos;

} else if (this.visibility == 'active') {

var newTodos = [];

this.todos.forEach(function (item) {

if (!item.completed) {

newTodos.push(item);

}

})

return newTodos;

} else if (this.visibility == 'completed') {

var newTodos = []

this.todos.forEach(function (item) {

if (item.completed == true) {

newTodos.push(item)

}

})

console.log(newTodos)

return newTodos;

}

}

}

});

</script>

<script>

//timestamp 現在的時間數字

//Math.floow 取整理

//Date.now 現在的時間

//this.todos.push() 新增一個物件進去todos

 
</script>

 
<style>

.completed {

text-decoration: line-through;

 
}

</style>


code學習筆記中心 發表在 痞客邦 留言(0) 人氣()



<div id="app">

<div class="input-group mb-3">

<div class="input-group-prepend">

<span class="input-group-text" id="basic-addon1">待辦事項</span>

</div>

<input type="text" class="form-control" v-model="newTodo" placeholder="準備要做的任務" v-on:keyup.enter="addTodo">

<div class="input-group-append">

<button class="btn btn-primary" v-on:click="addTodo" type="button">新增</button>

</div>

</div>

<div class="card text-center">

<div class="card-header">

<ul class="nav nav-tabs card-header-tabs">

<li class="nav-item">

<a class="nav-link" :class="{'active' : visibility == 'all'}" @click="visibility = 'all'" href="#">全部</a>

</li>

<li class="nav-item">

<a class="nav-link " :class="{'active' : visibility == 'active'}" @click="visibility = 'active' " href="#">進行中</a>

</li>

<li class="nav-item">

<a class="nav-link" :class="{'active' : visibility == 'completed'}" @click="visibility = 'completed' " href="#">已完成</a>

</li>

</ul>

</div>

<ul class="list-group list-group-flush text-left">

<li class="list-group-item"

@dblclick="editTodo(item)"

v-for="(item,key) in filteredTodos">

<div class="d-flex"

v-if ="item.id !== cacheTodo.id" >

<div class="form-check">

<input type="checkbox" v-model="item.completed" class="form-check-input" :id="item.id">

<label :class="{'completed' : item.completed} " class="form-check-label" :for="item.id">

{{ item.title }}

</label>

 

 
</div>

<button type="button" class="close ml-auto" aria-label="Close" v-on:click="removeTodo(item.id)">

<span aria-hidden="true">&times;</span>

</button>

</div>

<input type="text" class="form-control"

v-model="cacheTitle"

@keyup.esc="cancelEdit()"

v-if ="item.id == cacheTodo.id"

@keyup.enter="doneEdit(item)"

>

</li>

<!-- <li class="list-group-item">

<input type="text" class="form-control">

</li> -->

</ul>

<div class="card-footer d-flex justify-content-between">

<span>還有 3 筆任務未完成</span>

<a href="#">清除所有任務</a>

</div>

</div>

</div>

 
<script>

 
 

// 按到label 觸發id到input ,觸發input 就會觸發v-model false--->true---> item.completed變成false 就會加上completed 的class

var app = new Vue({

el: '#app',

data: {

newTodo: '',

todos: [{

id: '123', title: '你好', completed: false,

},

],

cacheTodo:{},

cachetitle:'',

visibility: 'all'

 
},

methods: {

addTodo: function () {

var value = this.newTodo.trim(); //空格會被刪掉

var timestamp = Math.floor(Date.now())

if (!value) { //value為空值時就不能執行

return;

}

this.todos.push({

id: timestamp,

title: value,

completed: false,

})

this.newTodo = '';

},

removeTodo: function (key) {

for (var i = 0; i < this.todos.length; i++) {

 
if (this.todos[i].id == key) {

this.todos.splice(i, 1)

}//當刪除那筆key的timestamp = todos裡的timestamp

}//就刪除當下的index

},

editTodo: function (item) {

this.cacheTodo =item;

this.cacheTitle=item.title

},

cancelEdit:function(){

this.cacheTodo='';

 
},

doneEdit: function(item){

console.log(item.title)

item.title= this.cacheTitle;

console.log(item.title)

this.cacheTitle ='';

console.log(item.title)

this.cacheTodo={};

console.log(item.title)

}

},

 

computed: {

filteredTodos: function () {

if (this.visibility == 'all') {

return this.todos;

} else if (this.visibility == 'active') {

var newTodos = [];

this.todos.forEach(function (item) {

if (!item.completed) {

newTodos.push(item);

}

})

return newTodos;

} else if (this.visibility == 'completed') {

var newTodos = []

this.todos.forEach(function (item) {

if (item.completed == true) {

newTodos.push(item)

}

})

console.log(newTodos)

return newTodos;

}

}

}

});

</script>

<script>

//timestamp 現在的時間數字

//Math.floow 取整理

//Date.now 現在的時間

//this.todos.push() 新增一個物件進去todos

 
</script>

 
<style>

.completed {

text-decoration: line-through;

 
}

</style>


code學習筆記中心 發表在 痞客邦 留言(0) 人氣()


<div id="app">
<div>
你已經點擊 <button class="btn btn-outline-secondary btn-sm" @click="counter += 1">{{ counter }}</button> 下。
</div>
<div>
你已經點擊 <button class="btn btn-outline-secondary btn-sm" @click="counter += 1">{{ counter }}</button> 下。
 
<counter-component></counter-component>
</div>
</div>
 
<script>
// 請在此撰寫 JavaScript
// vue compoent 可以新建元件
格式如下
一定要接function 和return
 
Vue.component('counter-component',{
data:function(){
return{counter:1}
},
template:` <div>
你已經點擊 <button class="btn btn-outline-secondary btn-sm" @click="counter += 1">{{ counter }}</button> 下。
</div>`
 
})
 
var app = new Vue({
el: '#app',
data: {
counter: 0
},
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()


<div id="app">
<div>
你已經點擊 <button class="btn btn-outline-secondary btn-sm" @click="counter += 1">{{ counter }}</button> 下。
</div>
<div>
你已經點擊 <button class="btn btn-outline-secondary btn-sm" @click="counter += 1">{{ counter }}</button> 下。
 
<counter-component></counter-component>
</div>
</div>
 
<script>
// 請在此撰寫 JavaScript
// vue compoent 可以新建元件
格式如下
一定要接function 和return
 
Vue.component('counter-component',{
data:function(){
return{counter:1}
},
template:` <div>
你已經點擊 <button class="btn btn-outline-secondary btn-sm" @click="counter += 1">{{ counter }}</button> 下。
</div>`
 
})
 
var app = new Vue({
el: '#app',
data: {
counter: 0
},
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()


<div id="app">
<h4>字串</h4>
{{ text }}
<input type="text" v-model ="text"class="form-control">
<hr>
{{ textarea }}
<textarea cols="30" rows="3" v-model ="textarea" class="form-control"></textarea>
<hr>
<h4>Checkbox 與 Radio</h4>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="check1">
<label class="form-check-label" for="check1"> ... </label>
</div>
<hr>
<div class="form-check">
<input type="checkbox" class="form-check-input"v-model=
"checkboxArray" id="check2" value="雞">
<label class="form-check-label" for="check2"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" v-model=
"checkboxArray" id="check3" value="豬">
<label class="form-check-label" for="check3"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" v-model=
"checkboxArray" id="check4" value="牛">
<label class="form-check-label" for="check4"></label>
</div>
<p>晚餐火鍋裡有 {{checkboxArray}}。</p>
<hr>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio2" value="雞">
<label class="form-check-label" for="radio2"></label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio3" value="豬">
<label class="form-check-label" for="radio3"></label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio4" value="牛">
<label class="form-check-label" for="radio4"></label>
</div>
<p>晚餐火鍋裡有 ...。</p>
<hr>
<h4>Select</h4>
<select name="" id="" class="form-control" v-model="selected">
<option value="請選擇">{{text}}</option>
<option value="雞"></option>
<option value="豬"></option>
</select>
</div>
 
<script>
var app = new Vue({
el: '#app',
data: {
text: '',
textarea: '',
checkbox1: false,
checkboxArray: [],
singleRadio: '',
selected: '',
},
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()


<div id="app">
<h4>字串</h4>
{{ text }}
<input type="text" v-model ="text"class="form-control">
<hr>
{{ textarea }}
<textarea cols="30" rows="3" v-model ="textarea" class="form-control"></textarea>
<hr>
<h4>Checkbox 與 Radio</h4>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="check1">
<label class="form-check-label" for="check1"> ... </label>
</div>
<hr>
<div class="form-check">
<input type="checkbox" class="form-check-input"v-model=
"checkboxArray" id="check2" value="雞">
<label class="form-check-label" for="check2"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" v-model=
"checkboxArray" id="check3" value="豬">
<label class="form-check-label" for="check3"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" v-model=
"checkboxArray" id="check4" value="牛">
<label class="form-check-label" for="check4"></label>
</div>
<p>晚餐火鍋裡有 {{checkboxArray}}。</p>
<hr>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio2" value="雞">
<label class="form-check-label" for="radio2"></label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio3" value="豬">
<label class="form-check-label" for="radio3"></label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio4" value="牛">
<label class="form-check-label" for="radio4"></label>
</div>
<p>晚餐火鍋裡有 ...。</p>
<hr>
<h4>Select</h4>
<select name="" id="" class="form-control" v-model="selected">
<option value="請選擇">{{text}}</option>
<option value="雞"></option>
<option value="豬"></option>
</select>
</div>
 
<script>
var app = new Vue({
el: '#app',
data: {
text: '',
textarea: '',
checkbox1: false,
checkboxArray: [],
singleRadio: '',
selected: '',
},
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()

 
<div id="app">
<input type="text" class="form-control" v-on:keyup.enter="reverseText" v-model="text">
 
<a v-bind:href="link" class="btn btn-primary mt-1" v-on:click="reverseText">反轉字串</a>
<div class="mt-3">
{{ newText }}
</div>
</div>
 
<script>
//v-on:click = @click
//v-bind:href =:href
var app = new Vue({
el: '#app',
data: {
text: '',
newText: '',
link:'http://www.google.com.tw'
},
// 請在此撰寫 JavaScript
methods: {
reverseText(event) {
this.newText = this.text.split('').reverse().join('');
}
}
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()

 
<div id="app">
<input type="text" class="form-control" v-on:keyup.enter="reverseText" v-model="text">
 
<a v-bind:href="link" class="btn btn-primary mt-1" v-on:click="reverseText">反轉字串</a>
<div class="mt-3">
{{ newText }}
</div>
</div>
 
<script>
//v-on:click = @click
//v-bind:href =:href
var app = new Vue({
el: '#app',
data: {
text: '',
newText: '',
link:'http://www.google.com.tw'
},
// 請在此撰寫 JavaScript
methods: {
reverseText(event) {
this.newText = this.text.split('').reverse().join('');
}
}
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()

 
<div id="app">
<input type="text" class="form-control" value="456" v-model="text">
<button class="btn btn-primary mt-1" v-on:click="reverseText">反轉字串</button>
<div class="mt-3">
{{ newText }}
</div>
</div>
//v-model ="text" 對應到value 取data裡的text的值
//只能用在這三個屬性 input select textarea
//v-on:click 對應到methods的reserseText的函數
<script>
var app = new Vue({
el: '#app',
data: {
text: '123',
newText: ''
},
// 請在此撰寫 JavaScript
methods:{
reverseText:function(){
this.newText = this.text.split('').reverse().join('')
 
}
 
}
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()

 
<div id="app">
<input type="text" class="form-control" value="456" v-model="text">
<button class="btn btn-primary mt-1" v-on:click="reverseText">反轉字串</button>
<div class="mt-3">
{{ newText }}
</div>
</div>
//v-model ="text" 對應到value 取data裡的text的值
//只能用在這三個屬性 input select textarea
//v-on:click 對應到methods的reserseText的函數
<script>
var app = new Vue({
el: '#app',
data: {
text: '123',
newText: ''
},
// 請在此撰寫 JavaScript
methods:{
reverseText:function(){
this.newText = this.text.split('').reverse().join('')
 
}
 
}
});
</script>

code學習筆記中心 發表在 痞客邦 留言(0) 人氣()

1 2 3
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。