Skip to content

Instantly share code, notes, and snippets.

@heroselohim
Last active March 15, 2017 19:01
Show Gist options
  • Save heroselohim/66978bf1b931ba83829124faf8a94922 to your computer and use it in GitHub Desktop.
Save heroselohim/66978bf1b931ba83829124faf8a94922 to your computer and use it in GitHub Desktop.
Vue 2 Basic Tests + Unified Shared Data // source https://jsbin.com/jovicis/2
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Vue 2.0 Unified Store">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Vue 2 Basic Tests</title>
<style id="jsbin-css">
.color-red
{
color:red;
}
.color-blue
{
color: blue;
}
.color-green
{
color: green;
}
.color-magenta
{
color: magenta;
}
.is-active
{
color: green;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div id="root">
ok, this seems cool
<p>
<input v-model="stuff">
</p>
<p v-model="stuff"></p>
<p>{{ stuff }}</p>
<ul style="list-style: none" class="btn-group">
<li v-for="character in characters" class="btn btn-primary">
{{character.name?character.name+' - ':''}} {{character.age}}
</li>
</ul>
<div class="btn-group">
<a href="https://youtube.com" v-for="character in characters" class="btn btn-primary">
{{character.name?character.name+' - ':''}} {{character.age}}
</a>
</div>
<h2 :class="colorClass">Color class</h2>
<button :class="{ 'is-active': isActive }" @click="toggleClass">Toggle class: {{ isActive }}</button>
<button @click="toggleColor">Toggle color</button>
</div>
<script id="jsbin-javascript">
var store = {
stuff: 'stuff textx',
isActive: true,
colorClass: "color-red",
characters: [
{name: 'joe', age: "17"},
{name: 'chris', age: "23"},
{name: 'robertin', age: "56"},
{name: 'heyman'}
],
currentColor: 1,
colors: [
'color-red',
'color-blue',
'color-green',
'color-magenta'
]
}
var vm = new Vue({
el: "#root",
data: store,
methods: {
toggleClass: function() {
this.isActive = !this.isActive;
},
toggleColor: function() {
this.currentColor++;
if (this.currentColor > this.colors.length) this.currentColor = 1;
this.colorClass = this.colors[this.currentColor-1];
}
}
});
</script>
<script id="jsbin-source-css" type="text/css">.color-red
{
color:red;
}
.color-blue
{
color: blue;
}
.color-green
{
color: green;
}
.color-magenta
{
color: magenta;
}
.is-active
{
color: green;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var store = {
stuff: 'stuff textx',
isActive: true,
colorClass: "color-red",
characters: [
{name: 'joe', age: "17"},
{name: 'chris', age: "23"},
{name: 'robertin', age: "56"},
{name: 'heyman'}
],
currentColor: 1,
colors: [
'color-red',
'color-blue',
'color-green',
'color-magenta'
]
}
var vm = new Vue({
el: "#root",
data: store,
methods: {
toggleClass: function() {
this.isActive = !this.isActive;
},
toggleColor: function() {
this.currentColor++;
if (this.currentColor > this.colors.length) this.currentColor = 1;
this.colorClass = this.colors[this.currentColor-1];
}
}
});
</script></body>
</html>
.color-red
{
color:red;
}
.color-blue
{
color: blue;
}
.color-green
{
color: green;
}
.color-magenta
{
color: magenta;
}
.is-active
{
color: green;
}
var store = {
stuff: 'stuff textx',
isActive: true,
colorClass: "color-red",
characters: [
{name: 'joe', age: "17"},
{name: 'chris', age: "23"},
{name: 'robertin', age: "56"},
{name: 'heyman'}
],
currentColor: 1,
colors: [
'color-red',
'color-blue',
'color-green',
'color-magenta'
]
}
var vm = new Vue({
el: "#root",
data: store,
methods: {
toggleClass: function() {
this.isActive = !this.isActive;
},
toggleColor: function() {
this.currentColor++;
if (this.currentColor > this.colors.length) this.currentColor = 1;
this.colorClass = this.colors[this.currentColor-1];
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment