Skip to content

Instantly share code, notes, and snippets.

@lonkecxd
Created September 30, 2017 15:39
Show Gist options
  • Save lonkecxd/e943b50e1a0257460f04e21f7d7df0ad to your computer and use it in GitHub Desktop.
Save lonkecxd/e943b50e1a0257460f04e21f7d7df0ad to your computer and use it in GitHub Desktop.
一个与Firebase连接的时光轴,可多人共享
// Initialize Firebase
var config = {
authDomain: "pretty-timeline.firebaseapp.com",
databaseURL: "https://pretty-timeline.firebaseio.com",
projectId: "pretty-timeline",
storageBucket: "pretty-timeline.appspot.com",
messagingSenderId: "652452531612"
};
firebase.initializeApp(config);
var eventRef = firebase.database().ref('events');
eventRef.on('value', function(snapshot) {
vm.events = snapshot.val();
});
var logs = [
{
year: 2014,
content: [{date:"9月24",tag:"开始写博客"}]
},
{
year: 2015,
content: [{tag:"成立工作室"}]
},
{
year: 2016,
content: [{tag:"进入外企"}]
}
]
var vm = new Vue({
el: "#app",
data:{
events: [],
},
methods:{
setTag(lid,cid){
let text = prompt("请输入新的文字",this.events[lid].content[cid].tag)
if(text){
this.events[lid].content[cid].tag = text
eventRef.child(lid).set(this.events[lid])
}
},
addTag(){
var k = eventRef.push({
year: new Date().getFullYear(),
content:[{
month: new Date().getMonth() + 1,
tag: "文字"
}]
})
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment