我正在使用回形针,导轨和vue。我的问题是如何使用vuejs2
获取图像的URLapp.js
var posts = #{ sanitize @posts.to_json }
var app = new Vue({
el: '#app',
data: {
posts: posts
}
})
app.haml
#app
%div{ 'v-for' => 'post in posts' }
%img{ ':src' => 'post.avatar' }
交
{ "id": 7, "title": "first post", "description": "lorem", "avatar_file_name": "batman.jpg", "avatar_content_type": "image/jpeg", "avatar_file_size": 32823, "avatar_updated_at": "2018-04-23T04:19:06.527Z" }
答案 0 :(得分:1)
您需要为.as_json
课程编写一个新的Post
函数或monkeypatch来读取以下内容:
def as_vue_json
{ id: id,
title: title,
avatar_url: avatar.url(:original),
description: description }
end