GithubHelp home page GithubHelp logo

Comments (19)

jacky-09 avatar jacky-09 commented on September 2, 2024 2

@yaowei9363 大佬,我在我的codesandbox里面改成这样是没有问题的,但是换到我自己前后端分离的地方就不行了,大佬能否帮我看看(实在没法放codesandbox)。
代码:

<template>
<div id="app">
    <div v-if="article.course"><h1>{{ article.course }}:{{ article.title }}</h1></div>
    <div v-else><h1>{{ article.title }}</h1></div>
    <br><br>
    <div id="article" align="left" v-html="articlebody"></div>
    <!--永远无法显示的目录-->
    <side-catalog v-if="show" class="catalog" v-bind="catalogProps"></side-catalog>
</div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import marked from 'marked';
import hljs from "highlight.js";
import 'highlight.js/styles/atom-one-light.css'
import axios from 'axios';
import SideCatalog from "vue-side-catalog";
import "vue-side-catalog/lib/vue-side-catalog.css";

export default {
    name: 'ArticleDetail',
    components: {
        SideCatalog,
    },
    data () {
        return {
            article: '',
            articlebody: '',
            catalogProps: {
                container: "#article",
                watch: true,
                height: "calc(100% - 100px)",
            }
        }
    },
    methods: {
        getArticle () {
            axios.get('http://127.0.0.1:8000/api/articles/' + this.$route.params.id)
            .then(this.getArticleSucc)
        },
        getArticleSucc (res) {
            this.article = res.data
            this.articlebody = res.data.body
            marked.setOptions({
            renderer: new marked.Renderer(),
            gfm: true,
            tables: true,
            breaks: false,
            pedantic: false,
            sanitize: false,
            smartLists: true,
            smartypants: false,
            highlight: function(code) {
                return hljs.highlightAuto(code).value;
            },
        })
            this.articlebody = marked(this.articlebody)
        },
    },
    mounted () {
        this.getArticle()
    },
}

</script>

<style scoped>
.catalog {
    position: fixed;
    top: 250px;
    right: 50px;
}
</style>

<style>
#article img {
    width: 90%;
    max-width: 100%;
    border-radius: 20px;
}
#article kbd {
    padding: .2rem .4rem;
    font-size: 87.5%;
    color: #fff;
    background-color: #212529;
    border-radius: .2rem;
}
</style>

这里确确实实是取到内容了,前面文章内容是正常显示的啊。

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024 1

不好意思,我这里使用的是前后端分离的项目,所以项目涉及后端的内容(比如说api),没法创建codesandbox按照模板的要求重现

from vue-side-catalog.

yaowei9363 avatar yaowei9363 commented on September 2, 2024 1

请参考这个 #7 看是否能解决问题

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024 1

博主,还是不行那。
代码:

<template>
<div id="app">
    <div v-if="article.course"><h1>{{ article.course }}:{{ article.title }}</h1></div>
    <div v-else><h1>{{ article.title }}</h1></div>
    <div id="article" align="left" v-html="articlebody"></div>
    <side-catalog class="catalog" v-bind="catalogProps"></side-catalog>
</div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import marked from 'marked';
import hljs from "highlight.js";
import 'highlight.js/styles/atom-one-light.css'
import axios from 'axios';
import SideCatalog from 'vue-side-catalog';
import 'vue-side-catalog/lib/vue-side-catalog.css'

export default {
    name: 'ArticleDetail',
    components: {
        SideCatalog,
    },
    data () {
        return {
            article: '',
            articlebody: '',
            catalogProps: {
                container: "#article",
                watch: true,
                height: "calc(100% - 100px)",
                title: "文章目录"
            }
        }
    },
    methods: {
        getArticle () {
            axios.get('http://127.0.0.1:8000/api/articles/' + this.$route.params.id)
            .then(this.getArticleSucc)
        },
        getArticleSucc (res) {
            this.article = res.data
            this.articlebody = res.data.body
            marked.setOptions({
            renderer: new marked.Renderer(),
            gfm: true,
            tables: true,
            breaks: false,
            pedantic: false,
            sanitize: false,
            smartLists: true,
            smartypants: false,
            highlight: function(code) {
                return hljs.highlightAuto(code).value;
            },
        })
            this.articlebody = marked(this.articlebody)
        },
    },
    mounted () {
        this.getArticle()
    },
}

</script>

<style>
.catalog {
    position: fixed;
    top: 250px;
    right: 50px;
}
</style>

但是还是没法显示出来,和原来一样。几乎已经和文档一样了,不知道什么情况,求大佬帮助。

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024 1

@yaowei9363 求大佬帮忙看看

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

还有一个补充,在文件最前面不用v-html换上其他文本是可以正常显示的

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

非常感谢

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

我这里的还是不太一样,不能设定setTimeout

from vue-side-catalog.

yaowei9363 avatar yaowei9363 commented on September 2, 2024

例子中的setTimeout 只是模拟异步请求,你可以把你marked.js解析过的文本替换例子中的vhtml看是否奏效。

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

好的,我再试试看

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

博主,我这里貌似已经把marked.js解析过的文本替换替换例子里面的vhtml,现在还是不行的

from vue-side-catalog.

yaowei9363 avatar yaowei9363 commented on September 2, 2024

codesandbox地址提供一下

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

还是谢谢大佬了,这个不算必要功能,先算了吧

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

大佬,我把这个重现到codesandbox上面了,一开始是可以的,但是请大佬刷新一下右侧显示区,就可以发现只剩一个标题了。
codesandbox地址:https://codesandbox.io/s/thirsty-lamport-523rs?file=/src/App.vue

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

@yaowei9363 大佬可以帮忙看看吗

from vue-side-catalog.

yaowei9363 avatar yaowei9363 commented on September 2, 2024

你可以使用v-ifv-html的内容准备好后再渲染catalog 例子

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

实在找不出来有什么问题啊

from vue-side-catalog.

yaowei9363 avatar yaowei9363 commented on September 2, 2024

请仔细看完给的例子,show是在给articlebody赋值后置为true

from vue-side-catalog.

jacky-09 avatar jacky-09 commented on September 2, 2024

谢谢大佬,问题解决了

from vue-side-catalog.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.