Skip to content

Commit 4a0de8e

Browse files
garethxNataliaTepluhina
authored andcommitted
Moving external example code to the examples folder (#2452)
* Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/50wL7mdz/ * Update index.html * Example app to pull code from example folder Once merged the URL https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-hello-world will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-hello-world * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/tdv8dt3s/ * Example app to pull code from example folder Once merged the URL https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-dependency-injection will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-dependency-injection * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/ttzutdxh/ * Example app to pull code from example folder Once deployed the URL https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-accessing-parent-component-instance will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-accessing-parent-component-instance * Moving example code to examples folder Example code from https://jsfiddle.net/09jvu65m/ * Example app to pull code from example folder Once merged the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-programmatic-event-listeners will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-programmatic-event-listeners * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/sbLgr0ad * Example app to pull code from example folder Once merged, the url https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-component-blog-post-example will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-component-blog-post-example * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/o3nycadu/ * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-components will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-components * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/b2qj69o1/ * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-components-with-binding will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-components-with-binding * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/65gLu2b6/ * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-state-transitions will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-state-transitions * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/Lp20op9o/ * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-keep-alive-with-dynamic-components will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-keep-alive-with-dynamic-components * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/sLrhk1bc/ * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-list-move-transitions will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-list-move-transitions * Moving example code to examples folder Example code in https://jsfiddle.net/chrisvfritz/tf2pjsc9/ * Moving example code to examples folder Example code from https://jsfiddle.net/chrisvfritz/bh8fLeds/ * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-priority-d-rules-unintended-consequences will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-priority-d-rules-unintended-consequences Likewise with the app referenced in the explanation text https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-priority-d-rules-correct-example / https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-priority-d-rules-correct-example * Moving example code to examples folder Code from https://gist.github.com/chrisvfritz/e2b6a6110e0829d78fa4aedf7cf6b235 * Add package.json Adding package.json required for import * Example app to pull code from example folder Once merged, the link https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-single-file-components will work. For testing, use https://codesandbox.io/s/github/garethx/vuejs.org/tree/master/src/v2/examples/vue-20-single-file-components
1 parent b421a52 commit 4a0de8e

File tree

50 files changed

+1133
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1133
-11
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dependency Injection Google Maps Demo</title>
5+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAHbknPTCvUSgWwU0jJ68m4h6b7vpyP6hM"></script>
6+
<script src="https://unpkg.com/vue"></script>
7+
<style>
8+
.map {
9+
width: 100%;
10+
height: 400px;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
<div id="app">
16+
<google-map>
17+
<google-map-marker v-bind:places="vueConfCities"></google-map-marker>
18+
</google-map>
19+
</div>
20+
21+
<script>
22+
Vue.component("google-map", {
23+
data: function() {
24+
return {
25+
map: null
26+
};
27+
},
28+
mounted: function() {
29+
this.map = new google.maps.Map(this.$el, {
30+
center: { lat: 0, lng: 0 },
31+
zoom: 1
32+
});
33+
},
34+
methods: {
35+
getMap: function(found) {
36+
var vm = this;
37+
function checkForMap() {
38+
if (vm.map) {
39+
found(vm.map);
40+
} else {
41+
setTimeout(checkForMap, 50);
42+
}
43+
}
44+
checkForMap();
45+
}
46+
},
47+
template: '<div class="map"><slot></slot></div>'
48+
});
49+
50+
Vue.component("google-map-marker", {
51+
props: ["places"],
52+
created: function() {
53+
var vm = this;
54+
vm.$parent.getMap(function(map) {
55+
vm.places.forEach(function(place) {
56+
new google.maps.Marker({
57+
position: place.position,
58+
map: map
59+
});
60+
});
61+
});
62+
},
63+
render(h) {
64+
return null;
65+
}
66+
});
67+
68+
new Vue({
69+
el: "#app",
70+
data: {
71+
vueConfCities: [
72+
{
73+
name: "Wrocław",
74+
position: {
75+
lat: 51.107885,
76+
lng: 17.038538
77+
}
78+
},
79+
{
80+
name: "New Orleans",
81+
position: {
82+
lat: 29.951066,
83+
lng: -90.071532
84+
}
85+
}
86+
]
87+
}
88+
});
89+
</script>
90+
</body>
91+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "vue-20-accessing-parent-component-instance",
3+
"version": "1.0.0",
4+
"description": "Vue.js example accessing Parent Component Instance using Google Maps.",
5+
"main": "index.html",
6+
"scripts": {
7+
"start": "serve"
8+
},
9+
"keywords": [],
10+
"license": "MIT",
11+
"devDependencies": {
12+
"serve": "^11.2.0"
13+
}
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"template": "static"
3+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Component Blog Post Example</title>
5+
<script src="https://unpkg.com/vue"></script>
6+
</head>
7+
<body>
8+
<div id="blog-post-demo" class="demo">
9+
<blog-post
10+
v-for="post in posts"
11+
v-bind:key="post.id"
12+
v-bind:title="post.title"
13+
></blog-post>
14+
</div>
15+
16+
<script>
17+
Vue.component("blog-post", {
18+
props: ["title"],
19+
template: "<h3>{{ title }}</h3>"
20+
});
21+
22+
new Vue({
23+
el: "#blog-post-demo",
24+
data: {
25+
posts: []
26+
},
27+
created: function() {
28+
// Alias the component instance as `vm`, so that we
29+
// can access it inside the promise function
30+
var vm = this;
31+
// Fetch our array of posts from an API
32+
fetch("https://jsonplaceholder.typicode.com/posts")
33+
.then(function(response) {
34+
return response.json();
35+
})
36+
.then(function(data) {
37+
vm.posts = data;
38+
});
39+
}
40+
});
41+
</script>
42+
</body>
43+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "vue-20-component-blog-post-example",
3+
"version": "1.0.0",
4+
"description": "Dynamically passing props, like when fetching posts from an API.",
5+
"main": "index.html",
6+
"scripts": {
7+
"start": "serve"
8+
},
9+
"keywords": [],
10+
"license": "MIT",
11+
"devDependencies": {
12+
"serve": "^11.2.0"
13+
}
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"template": "static"
3+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dependency Injection Google Maps Demo</title>
5+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAHbknPTCvUSgWwU0jJ68m4h6b7vpyP6hM"></script>
6+
<script src="https://unpkg.com/vue"></script>
7+
<style>
8+
.map {
9+
width: 100%;
10+
height: 400px;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
<div id="app">
16+
<google-map>
17+
<google-map-marker v-bind:places="vueConfCities"></google-map-marker>
18+
</google-map>
19+
</div>
20+
21+
<script>
22+
Vue.component("google-map", {
23+
provide: function() {
24+
return {
25+
getMap: this.getMap
26+
};
27+
},
28+
data: function() {
29+
return {
30+
map: null
31+
};
32+
},
33+
mounted: function() {
34+
this.map = new google.maps.Map(this.$el, {
35+
center: { lat: 0, lng: 0 },
36+
zoom: 1
37+
});
38+
},
39+
methods: {
40+
getMap: function(found) {
41+
var vm = this;
42+
function checkForMap() {
43+
if (vm.map) {
44+
found(vm.map);
45+
} else {
46+
setTimeout(checkForMap, 50);
47+
}
48+
}
49+
checkForMap();
50+
}
51+
},
52+
template: '<div class="map"><slot></slot></div>'
53+
});
54+
55+
Vue.component("google-map-marker", {
56+
inject: ["getMap"],
57+
props: ["places"],
58+
created: function() {
59+
var vm = this;
60+
vm.getMap(function(map) {
61+
vm.places.forEach(function(place) {
62+
new google.maps.Marker({
63+
position: place.position,
64+
map: map
65+
});
66+
});
67+
});
68+
},
69+
render(h) {
70+
return null;
71+
}
72+
});
73+
74+
new Vue({
75+
el: "#app",
76+
data: {
77+
vueConfCities: [
78+
{
79+
name: "Wrocław",
80+
position: {
81+
lat: 51.107885,
82+
lng: 17.038538
83+
}
84+
},
85+
{
86+
name: "New Orleans",
87+
position: {
88+
lat: 29.951066,
89+
lng: -90.071532
90+
}
91+
}
92+
]
93+
}
94+
});
95+
</script>
96+
</body>
97+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "vue-20-dependency-injection",
3+
"version": "1.0.0",
4+
"description": "Vue.js Dependency Injection example using Google Maps.",
5+
"main": "index.html",
6+
"scripts": {
7+
"start": "serve"
8+
},
9+
"keywords": [],
10+
"license": "MIT",
11+
"devDependencies": {
12+
"serve": "^11.2.0"
13+
}
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"template": "static"
3+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dynamic Components Example</title>
5+
<script src="https://unpkg.com/vue"></script>
6+
<style>
7+
.tab-button {
8+
padding: 6px 10px;
9+
border-top-left-radius: 3px;
10+
border-top-right-radius: 3px;
11+
border: 1px solid #ccc;
12+
cursor: pointer;
13+
background: #f0f0f0;
14+
margin-bottom: -1px;
15+
margin-right: -1px;
16+
}
17+
.tab-button:hover {
18+
background: #e0e0e0;
19+
}
20+
.tab-button.active {
21+
background: #e0e0e0;
22+
}
23+
.tab {
24+
border: 1px solid #ccc;
25+
padding: 10px;
26+
}
27+
</style>
28+
</head>
29+
<body>
30+
<div id="dynamic-component-demo" class="demo">
31+
<button
32+
v-for="tab in tabs"
33+
v-bind:key="tab.name"
34+
v-bind:class="['tab-button', { active: currentTab.name === tab.name }]"
35+
v-on:click="currentTab = tab"
36+
>
37+
{{ tab.name }}
38+
</button>
39+
40+
<component v-bind:is="currentTab.component" class="tab"></component>
41+
</div>
42+
43+
<script>
44+
var tabs = [
45+
{
46+
name: "Home",
47+
component: {
48+
template: "<div>Home component</div>"
49+
}
50+
},
51+
{
52+
name: "Posts",
53+
component: {
54+
template: "<div>Posts component</div>"
55+
}
56+
},
57+
{
58+
name: "Archive",
59+
component: {
60+
template: "<div>Archive component</div>"
61+
}
62+
}
63+
];
64+
65+
new Vue({
66+
el: "#dynamic-component-demo",
67+
data: {
68+
tabs: tabs,
69+
currentTab: tabs[0]
70+
}
71+
});
72+
</script>
73+
</body>
74+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "vue-20-dynamic-components-with-binding",
3+
"version": "1.0.0",
4+
"description": "Showing binding to a component's options object.",
5+
"main": "index.html",
6+
"scripts": {
7+
"start": "serve"
8+
},
9+
"keywords": [],
10+
"license": "MIT",
11+
"devDependencies": {
12+
"serve": "^11.2.0"
13+
}
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"template": "static"
3+
}

0 commit comments

Comments
 (0)