现在有这么一个需求,就是一段文本中有个别地方需要加特效,比如弹框什么的,但是位置不确定,然后决定数据格式这样写 {content:'我是文本'+'\ <component v\-bind\:\"testPython \"\:inputValue\=\"\"\>\<\/component\>'+'接着是文本'}
,
中间的有一个定义好的组件testPython,组件里是这样写的
<template>
<section class="financial-list">
<section class="collect" >
<aside>
<h2 class="title">{{newsDate.title}}</h2>
<div class="content" v-html="newsDate.content"></div>
<testPython></testPython>
<section class="Cleft clearfix">
<img class="fl" src="../../assets/2.png" style="width:0.24rem;height:0.2rem;">
<span class="fl">{{newsDate.author_name}}</span>
</section>
<section class="Cright">
<img src="../../assets/1.png" style="width:0.2rem;height:0.2rem;">
<span>{{newsDate.date | getYMD}}</span>
</section>
<div style="clear: both"></div>
</aside>
<aside>
<img :src="newsDate.thumbnail_pic_s" style="border-radius: 0.2rem;" @click="heightValue">
</aside>
<div style="clear: both"></div>
</section>
</section>
</template>
<script>
import testPython from "../../components/testPython.vue"
export default {
name: 'NewsCell',
components:{
testPython
},
props: {
newsDate: Object
},
data () {
return {
}
},
computed: {
},
methods: {
heightValue:function(){
console.log("shenmegui");
}
}
}
</script>
<style scoped>
.financial-list {
width: 100%;
height: 100%;
background-color: white;
padding: 0.28rem 0;
border-bottom: 1px solid #ccc;
}
.financial-list .collect {
width: 92%;
margin: 0 auto;
}
.financial-list .collect aside:nth-of-type(1) {
width: 63%;
float: left;
}
.financial-list .collect aside:nth-of-type(2) {
width: 32%;
float: left;
margin-left: 0.3rem;
}
.financial-list .collect h2 {
width: 100%;
/*height: 0.96rem;*/
font-size:0.6rem;
color:orange;
/*line-height: 0.48rem;*/
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
overflow: hidden;
}
.financial-list .collect aside:nth-of-type(2) img {
width: 100%;
height: 100%;
}
.financial-list .collect aside .Cleft {
width: 45%;
float: left;
margin-top: 0.66rem;
}
.financial-list .collect aside .Cleft span{
display: block;
width: 1.4rem;
margin-left: 0.05rem;
white-space: nowrap;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
overflow: hidden;
}
.financial-list .collect aside .Cright {
width: 55%;
float: right;
margin-top: 0.66rem;
}
.financial-list .collect aside .Cright span{
display: inline-block;
margin: 0.04rem 0 0 0.05rem;
}
.financial-list .collect aside span {
font-size: 0.2rem;
color: #999999;
}
.financial-list .collect aside .Cleft img,
.financial-list .collect aside .Cright img {
width: 0.18rem;
height: 0.24rem;
margin-top: 0.09rem;
}
.content{
font-size:0.55rem;
}
</style>
父组件请求后props给子组件,子组件拿到数据后通过v-html插入template里,然后通过import引入定义好的组件,结果是子组件不渲染,
大神们看看是思路问题,还是那块有问题,用的是vue2,查资料vue1 的Vue.compile( template )方法好像不好用了
1.官网给的demo里是v-bind:is 的写法
2.这里的这个组件根本没有渲染,vue在分析template的时候会将template里的html转化成render写法来生成html,你这里依然是component,vue解析器在执行render('component',...)的时候并没有识别到这是一个动态组件,可能是你没加is的原因。
3.这种时候,如果你熟悉react的jsx的话,用jsx会比较好一些,vue官方提供了这么一个插件:babel-plugin-transform-vue-jsx