我正在使用 Evan You 的如何将 HTML 转换为 markdown 的示例 - https://jsfiddle.net/yyx990803/oe7axeab/。
通过安装marked
包npm
然后实现它会导致错误,'marked' is not defined
.
如果我cdn
在文件中包含链接index.html
,则降价会转换为“0”,我会收到错误消息:
[Vue warn]: Property or method "marked" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
编辑:
我试图将它包括在我main.js
的如下:
import App from './App.vue';
import router from './router';
import store from './store';
import './css/main.css';
import i18n from './i18n';
import marked from 'marked';
const debugSetting = window.ApplicationConfig.DEBUG;
Vue.config.debug = debugSetting;
Vue.config.productionTip = false;
new Vue({
router,
store,
i18n,
marked,
render: function(h) {
return h(App);
},
}).$mount('#app');
但这感觉不对,因此为什么我尝试使用cdn
just 看看这至少是否有效。
零件
<template>
<main-layout>
<div class="wrapper" v-html="terms | marked"></div>
</main-layout>
</template>
<script>
import MainLayout from '@/layouts/Main.vue';
import { getTerms } from '../api';
export default {
name: 'Terms',
components: {
MainLayout,
},
data() {
return {
terms,
};
},
filters: {
marked: marked,
},
async mounted() {
try {
const response = await getTerms();
if (response) {
this.terms = response.data;
console.log(this.terms);
}
} catch (err) {
console.log(err);
}
},
};
</script>