Skip to content

Instantly share code, notes, and snippets.

@surmon-china
Created February 25, 2017 19:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surmon-china/b5b4be00909bdded93fdf9074c5c8a9b to your computer and use it in GitHub Desktop.
Save surmon-china/b5b4be00909bdded93fdf9074c5c8a9b to your computer and use it in GitHub Desktop.
vue中使用disqus
/**
* Vue-disqus
* @author Surmon.me
*/
const DisqusComponent = require('./disqus.vue')
const disqus = {
install: function(Vue) {
Vue.component('disqus-box', DisqusComponent)
}
}
module.exports = disqus
<template>
<div id="disqus_thread" class="disqus-comment"></div>
</template>
<script>
export default {
name: 'vue-disqus',
props: {
url: {
required: true
},
identifier: {
required: true
}
},
mounted() {
console.log(window.DISQUS)
if (window.DISQUS) {
this.reset(window.DISQUS)
return
}
this.init()
},
methods: {
reset(disqus) {
const self = this
disqus.reset({
reload: true,
config() {
this.page.url = self.url
this.page.identifier = self.identifier
}
})
},
init() {
const self = this
window.disqus_config = function() {
this.page.url = self.url
this.page.identifier = self.identifier
}
setTimeout(() => {
(function() {
var d = document, s = d.createElement('script');
s.src = '//surmon.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
}, 0)
}
}
}
</script>
<style lang="scss">
@import '~assets/sass/mixins';
@import '~assets/sass/variables';
.disqus-comment {
padding: 1em;
background-color: $module-bg;
.post-list {
.post {
.post-content {
margin-bottom: 30px;
}
}
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment