今天來點輕鬆的,我們幫文章實作一些細節
如果文章內容是圖片連結的話,轉換成圖片
it('內容如果是圖片連結,要顯示圖片', () => {
let showButton = '.post:nth-child(2) .show-btn'
let postContent = '.post:nth-child(2) .content'
click( showButton )
picture(posts[1].content, `${postContent} img`)
})
<p v-if="post.content && post.show" class="mt-2 content">
<img class="img-fluid" v-if="isImage(post.content)" :src="post.content">
<span v-else v-text="post.content"></span>
</p>
methods: {
...
isImage: function (content) {
return content.match(/\.(jpeg|jpg|gif|png)$/) != null
}
},